Php twitter流式api代替搜索api
我正在使用twitters搜索API来查看所有使用我想要查看的特定标签的tweet 但是,我想使用stream函数,因此,我只获取最近的,因此,我可以存储它们Php twitter流式api代替搜索api,php,twitter,Php,Twitter,我正在使用twitters搜索API来查看所有使用我想要查看的特定标签的tweet 但是,我想使用stream函数,因此,我只获取最近的,因此,我可以存储它们 <?php global $total, $hashtag; $hashtag = $_POST['hash']; $total = 0; function getTweets($hash_tag, $page) { global $to
<?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,
但在那之后我需要改变什么,我不知道该做什么
显然,我知道我需要编写数据库sql,但我只想先捕获流并查看它
我该怎么做?我一直在使用的代码对捕获流没有任何好处吗?似乎不可能使用流API获取哈希标记 使用搜索API几乎是唯一的解决方案。只需使用AJAX内容刷新即可获得所有新推文。整体效果基本相同,除非您希望将tweet存储在数据库中,在这种情况下,必须防止保存重复的tweet