2012-10-01 74 views
0

我正在使用twitters搜索API来查看所有使用我想查看的特定hashtag的tweet。twitter streaming api而不是搜索api

但是,我想使用流功能,所以,我只能得到最近的,所以,我可以将它们存储。

<?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,但我想只是先捕获流并查看它。

我该怎么做?我一直在使用的代码对于捕获流而言没有任何好处?

回答

0

似乎不可能使用流API获取井号标签。

使用搜索API几乎是唯一的解决方案。只需使用AJAX内容刷新即可获取所有新推文。总体效果几乎相同,除非您想将推文存储在数据库中,以防止重复文件被保存。