Php 基于hashtags的总tweet计数器
我正在基于php中当前的tweet计数构建一个事件,该事件包含一个特定的hashtag。 在主页上我有一个计数器,上面写着:“到目前为止推特:xxx”。我使用了以下php脚本:Php 基于hashtags的总tweet计数器,php,mysql,twitter,Php,Mysql,Twitter,我正在基于php中当前的tweet计数构建一个事件,该事件包含一个特定的hashtag。 在主页上我有一个计数器,上面写着:“到目前为止推特:xxx”。我使用了以下php脚本: global $total, $hashtag; $hashtag = '#somehashtag'; $total = 0; function getTweets($hash_tag, $page) { global $total, $hashtag; $url = 'http://search.twitt
global $total, $hashtag;
$hashtag = '#somehashtag';
$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);
$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);
接下来,我将结果保存在我的数据库中:
$updateCount = "UPDATE tweets SET currentcount = '$total'";
$doQuery = mysql_query($updateCount, $con) or die(mysql_error());
此脚本由cronjob运行,它每2分钟触发一次脚本。
它很好用。但是这个脚本只返回1500条tweet,因为twitter不允许更多的tweet
我怎样才能继续记录当前的推文数量?我知道没有办法超越推特api的最大推特数。但也许通过时间或数据库检查?
提前谢谢 我会这样做:
- 将您在数据库中获得的最后一个tweets id与当前计数一起保存
- 在下一次运行时,获取上一条推文的推文,将推文数添加到计数中,并使用新的最后一条推文更新最后一条推文条目李>
- 起泡,冲洗,重复
since\u id
参数:
自_id:返回状态id大于给定id的tweet