Twitter限速检查和缓存

时间:2011-08-26 10:06:09

标签: php twitter

我想检查一下我是如何检查Twitter结果的API请求限制的问题。即使使用下面的方法,我仍然会偶尔出现错误,我没有要显示的推文。缓存部分工作正常,我只是不确定我是否正确地检查速率限制状态?感谢

            // Check allowed requests left from server IP - get json response and decode to array
        $curr_rate = json_decode(file_get_contents("http://api.twitter.com/1/account/rate_limit_status.json", TRUE)); 

        // Check remaining hits allowed
        if ($curr_rate AND $curr_rate->remaining_hits > 10)
        {   
            $twitter_data = json_decode(file_get_contents("http://twitter.com/status/user_timeline/userID.json?count=3", TRUE));

            // Cache twitter feed to avoid rate limit issue
            $this->cache->set('tweets', $twitter_data);
        }   
        else
        {
            // Don't make another request, use cached tweets
            $twitter_data = $this->cache->get('tweets');
        }

1 个答案:

答案 0 :(得分:0)

你的支票很好。

然而,当我点击

http://api.twitter.com/1/account/rate_limit_status.json

100次,仍然出现相同的数字