2011-02-28 62 views
2

是否有任何方法来保持包含特定标签或单词的推文计数?例如,保持包含#标签的所有推文的计数,或包含'iphone'的所有推文?用标签计数推文

回答

3

为获取计数包括hashtag(#)这个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; 
?> 

谢谢..

+3

这看起来不错,但不会给你一个完整的计数,因为Twitter API给你每个请求最多100条推文,并且不会让你进一步下去,直到第15页或第16页。所以最多这会给你1500左右,即使有更多。 – Sorcy 2012-03-23 10:52:53

0

你可以使用一个类似的服务,以DataSift跟踪包含在某些井号标签或关键字的推文即时的。他们也将在今年夏天发布Historics service,允许您回溯至2010年1月