dongpai6567 2013-08-13 21:21
浏览 57
已采纳

按主题标签搜索Twitter API v1.1 - 否返回旧结果

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?

  • 写回答

1条回答 默认 最新

  • dsij89625 2013-08-13 21:54
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘