Miguel
Miguel

Reputation: 15

Search by hashtag Twitter API v1.1 - No Returns Old Results

I'm doing a search for hashtags using the new api Twitter (v 1.1) and it works for some results. But for older tweets do not return a result.

My code:

    $this->load->library("TwitterAPIExchange", $settings);

    /** Perform the request and echo the response **/
    $twitter = new TwitterAPIExchange($settings);

    /** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/
    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod = "GET";

    //hashtag
    $hashtag = "#vmb2012";
    //Method search parameters GET
    $getfield = "?q=$hashtag&result_type=mixed&count=100";
    //Counter tweets
    $count = 0;

    /** Search global tweets for a hashtag **/
    $result = json_decode( $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest() );      

    if(!empty($result))
    {
        //increases the qty of tweets
        $count = isset($result->statuses) ? count($result->statuses) : 0;

        //if you have more results, performs the query again                                
        while($result->search_metadata && isset($result->search_metadata->next_results))
        {
            //search parameters of the next result
            $getfield = $result->search_metadata->next_results;
            $result = json_decode( $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest() );
            $count += count($result->statuses);             
        }                   
    }

    echo "Hashtag: ".$hashtag." <br>";
    echo "Counter: ".$count;

can anyone help me?

Upvotes: 0

Views: 1742

Answers (1)

Lo&#239;c Jazon
Lo&#239;c Jazon

Reputation: 56

From dev.twitter.com

Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.

I hope this was helpful

Upvotes: 2

Related Questions