繁体   English   中英

Twitter流式API而不是搜索api

[英]twitter streaming api instead of search api

我正在使用Twitters搜索API来查看使用要查看的特定主题标签的所有tweet。

但是,我想使用流函数,因此,我只获取最新的流,因此可以存储它们。

  <?php
        global $total, $hashtag;
        $hashtag = $_POST['hash'];
        $total = 0;
        function getTweets($hash_tag, $page) {
              global $total, $hashtag;
              $url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
              $url .= 'page='.$page;    
              $ch = curl_init($url);
              curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
              $json = curl_exec ($ch);
              curl_close ($ch);
              echo "<pre>";    
              $json_decode = json_decode($json);
              print_r($json_decode->results);

              $json_decode = json_decode($json);        
              $total += count($json_decode->results);    
              if($json_decode->next_page){
                   $temp = explode("&",$json_decode->next_page);        
                   $p = explode("=",$temp[0]);                
                   getTweets($hashtag,$p[1]);
              }        
        }

        getTweets($hashtag,1);
        echo $total;
  ?>

上面的代码是我一直在使用的搜索我想要的推文的代码。

我需要做些什么来更改它,以便我可以流化这些推文?

我知道我将不得不使用流URL https://api.twitter.com/1.1/search/tweets.json ,但是在那之后我需要更改的地方是我不知道该怎么做。

显然,我知道我需要编写数据库sql,但我想先捕获流并查看它。

我该怎么做? 我一直使用的代码对捕获流没有好处吗?

似乎不可能使用流API来获取主题标签。

使用搜索API几乎是唯一的解决方案。 只需使用AJAX内容刷新即可获取所有新推文。 除非您要将推文存储在数据库中,否则总体效果几乎是相同的,在这种情况下,必须防止保存重复项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM