【发布时间】:2014-12-11 07:24:19
【问题描述】:
我正在基于 php 中的当前推文计数构建一个包含特定主题标签的事件。 在主页上,我有一个计数器,上面写着:“到目前为止的推文:xxx”。我使用了这个 php 脚本:
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());
此脚本由每 2 分钟触发一次脚本的 cronjob 运行。 它工作正常。但是这个脚本只返回 1500 条推文,因为 twitter 不再允许。
我如何仍能跟踪当前的推文数量?我知道没有办法超过 twitter api 的最大推文。但也许通过时间或数据库检查? 提前致谢!
【问题讨论】: