【问题标题】:Twitter rate limit check and cachingTwitter 速率限制检查和缓存
【发布时间】:2011-08-26 18:10:39
【问题描述】:

我想检查我检查 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');
        }

【问题讨论】:

  • 你可以直接从标题中检查你的速率限制,如果我没记错的话,Twitter 会发送一个 X-Rate-Limit。

标签: php twitter


【解决方案1】:

你的支票没问题。

但是,当我点击

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2011-11-16
    • 2015-07-09
    • 2012-01-20
    相关资源
    最近更新 更多