Instagram每小时最大请求数(30)超过了?

时间:2014-01-16 12:42:50

标签: php api oauth instagram

{
   "code":420,
   "error_type":"OAuthRateLimitException",
   "error_message":"You have exceeded the maximum number of requests per hour. You have performed a total of 253 requests in the last hour. Our general maximum request limit is set at 30 requests per hour."
}

我刚注意到我正在关注的客户网站已经停止显示Instagram Feed,所以我将源URL直接加载到浏览器中,我得到了上述错误。我认为一小时内不应该有253个请求,但在谷歌搜索这个问题时,我遇到有人说这是因为API在每次请求时都登录了。可悲的是,我之前“已经”继承了这段代码,之前并没有真正使用过Instagram API,除了之前修复过这个网站的错误。

客户端站点位于WordPress中,因此我将代码包装起来以获取函数中的图像:

function get_instagram($user_id=USERID,$count=6,$width=190,$height=190){
    $url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?access_token=ACCESSTOKEN&count='.$count;

    // Also Perhaps you should cache the results as the instagram API is slow
    $cache = './'.sha1($url).'.json';
    if(file_exists($cache) && filemtime($cache) > time() - 60*60){
        // If a cache file exists, and it is newer than 1 hour, use it
        $jsonData = json_decode(file_get_contents($cache));
    } else {
        $jsonData = json_decode((file_get_contents($url)));
        file_put_contents($cache,json_encode($jsonData));
    }
    $result = '<a style="background-image:url(/wp-content/themes/iwear/inc/img/instagram-background.jpg);" target="_BLANK" href="http://www.instagr.am" class="lc-box lcbox-4 instagram">'.PHP_EOL.'<ul>'.PHP_EOL;
    foreach ($jsonData->data as $key=>$value) {
        $result .= "\t".'<li><img src="'.$value->images->low_resolution->url.'" alt="'.$value->caption->text.'" data-width="'.$width.'" data-height="'.$height.'" /><div class="lc-box-inner"><div class="title"><h2>images</h2></div><div class="description">'.$value->caption->text.'</div></div></li>'.PHP_EOL;
    }
    $result .= '</ul></a>'.PHP_EOL;

    return $result;
}

但正如我所说,此代码已停止工作。有什么办法可以优化它来实际工作吗?我还注意到在(可能是被盗的)Instagram中提到了一个缓存,但它实际上并不是缓存,所以这也可能是一个解决方案

由于

1 个答案:

答案 0 :(得分:3)

尝试在instagram中注册新客户端,然后更改

$url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?access_token=ACCESSTOKEN&count='.$count;

$url = https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?client_id=CLIENT_ID&count='.$count;

其中CLIENT_ID是您最近创建的客户端的客户端ID。