使用Twitter搜索API按日期对tweet进行排序


Sort the tweets by date using Twitter Search API

我已经编写了一个应用程序,使用twitter API搜索特定关键字的tweet,但我试图找到一种方法来首先显示最新的tweet,我无法找到一种方法来排序作为响应收到的tweet。

我指的是链接https://dev.twitter.com/docs/api/1.1/get/search/tweets,下面是我的代码

我已经包含了所有必需的文件并设置了所有必需的参数

    function search(array $query)
{
  $toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
  return $toa->get('search/tweets', $query);
}
$query = array(
  "q" => "Sachin Tendulkar",
  "count" => 10,
  "result_type" => "popular"
 );
$results = search($query);

如果有任何帮助,我将不胜感激。由于

要显示最新的tweet,您应该使用result_type作为recent

$query = array(
  "q" => "Sachin Tendulkar",
  "count" => 10,
  "result_type" => "recent"
 );

result_type参数详细信息:

  • mixed:在响应中包括流行结果和实时结果。
  • recent:只返回最近的结果
  • popular:只返回响应中最流行的结果。