opensource-developer
opensource-developer

Reputation: 3068

Sort the tweets by date using Twitter Search API

I have written an application that searches tweets for a specific keyword using the twitter API, but i am trying to find a way to display the latest tweets first, i am unable to find a way to sort the tweets received as a response.

I am referring to link https://dev.twitter.com/docs/api/1.1/get/search/tweets and below is my code

I have included all necessary files and set all required parameters

    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);

Any help on this would be appreciated. Thanks

Upvotes: 1

Views: 5916

Answers (1)

Yuva Raj
Yuva Raj

Reputation: 3881

To display the latest tweet, you should use result_type as recent.

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

More about result_type paramater :

  • mixed: Include both popular and real time results in the response.
  • recent: return only the most recent results in the response.
  • popular: return only the most popular results in the response.

Upvotes: 1

Related Questions