0

我正在使用新的 api Twitter (v 1.1) 搜索主题标签,它适用于某些结果。但是对于较旧的推文不返回结果。

我的代码:

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

谁能帮我?

4

1 回答 1

2

来自dev.twitter.com

请注意,Twitter 的搜索服务以及扩展的搜索 API 并不意味着是推文的详尽来源。并非所有推文都会被索引或通过搜索界面提供

我希望这可以帮到你

于 2013-08-13T21:54:46.183 回答