【问题标题】:Count tweets with hashtag计算带有标签的推文
【发布时间】:2014-12-11 01:32:54
【问题描述】:

有没有什么方法可以统计包含特定主题标签或单词的推文?例如,统计所有包含主题标签、#apple 的推文或所有包含“iphone”的推文?

【问题讨论】:

    标签: twitter


    【解决方案1】:

    这个获取计数标签(#)twitter的php源代码

    <?php
       global $total, $hashtag;
       //$hashtag = '#supportvisitbogor2011';
       $hashtag = '#australialovesjustin';
       $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;
    ?>
    

    谢谢..

    【讨论】:

    • 这看起来不错,但不会给你一个完整的计数,因为 Twitter API 为你提供每个请求最多 100 条推文,并且直到第 15 页或第 16 页才让你继续下去。所以最多这个会给你大约 1500 并且不会更多,即使还有更多。
    【解决方案2】:

    您可以使用DataSift 之类的服务来实时跟踪包含特定主题标签或关键字的推文。他们还将在今年夏天发布Historics service,让您可以追溯到 2010 年 1 月

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2015-03-02
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      相关资源
      最近更新 更多