[英]Twitter rate limit check and caching
我想檢查我如何檢查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');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.