I want to check if there's an issue with how I'm checking API request limit for twitter results. Even with the approach below, I still get the occasional error where I have no tweets to display. The caching part works fine, I'm just not sure if i'm going the right way about checking the rate limit status? Thanks
// 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');
}
Your checks are fine.
However, when I hit
http://api.twitter.com/1/account/rate_limit_status.json
100 times, there are still same numbers appearing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.