简体   繁体   English

如何在没有限制费率问题的情况下关注使用Instagram API的用户?

[英]How can I follow users using the instagram API without the limit rate issue?

I want to follow a list of user ids in instagram. 我想在instagram中关注用户ID列表。 I made the list and when I try to send the follow request using the api, I get this error: Client request limit reached (code: 400) 我做了列表,当我尝试使用api发送跟随请求时,我收到此错误:达到客户端请求限制(代码:400)

The developer documentation says: "You are limited to 5000 requests per hour per access_token or client_id overall." 开发人员文档说:“每个access_token或client_id整体限制为每小时5000个请求。”

but when I get this error, my code hardly followed 50 user ids! 但是当我收到此错误时,我的代码几乎没有跟踪50个用户ID!

And one more thing, when I got this error I tried to follow people on the instagram app directy (not using the api) and there were no issues! 还有一件事,当我收到这个错误时,我试图在Instagram应用程序直接跟踪人们(不使用api)并且没有问题!

This is some part of my code that get's this error: 这是我的代码中的一部分,它会出现此错误:

foreach ($usersArr as $user) {
$i++;
$url = 'https://api.instagram.com/v1/users/'.$user->id.'/relationship?access_token='. $accessToken;
$data = 'action=follow';
$resultObj = json_decode(sendPostData($url, $data));
$responseCode = $resultObj->meta->code;
$errorMsg = $resultObj->meta->error_message;
if ($responseCode != 200)
    echo "\"" . $errorMsg . "\" AT " . date('Y-m-d H:i:s') . "\n\n";
while ($responseCode != 200){
    sleep(60);
    $resultObj = json_decode(sendPostData($url, $data));
    $responseCode = $resultObj->meta->code;
    if ($responseCode != 200) {
        $errorMsg = $resultObj->meta->error_message;
        echo "STILL \"" . $errorMsg . "\" AT " . date('Y-m-d H:i:s') . "\n\n";
    }
    elseif($responseCode == 200){
        echo "Limit Finished At: " . date('Y-m-d H:i:s') . "\n\n";
        break;
    }
}
echo "User NO. " .$i . " has been followed!" . "\n\n";
}

Thanks a lot :) 非常感谢 :)

My experience with the relationship endpoint of the API is that you are limited to around 160 requests per hour. 我对API关系端点的体验是,您每小时只能处理大约160个请求。 This appears to be shared with all the actions (follow/unfollow/block/unblock/approve/deny). 这似乎与所有操作共享(follow / unfollow / block / unblock / approve / deny)。 I have been unable to find anything that allows you to determine in advance how many requests you have left before you exceed your limit (unlike the X-Ratelimit-Remaining header in for the overall request limit), and I have noticed that a any attempt to use the endpoint is added to your request count, whether or not it succeeds. 我一直无法找到任何允许您提前确定在超出限制之前剩余的请求数量的任何内容(与整体请求限制中的X-Ratelimit-Remaining标头不同),我注意到任何尝试无论是否成功,使用端点都会添加到您的请求计数中。

Because my particular app is processing for multiple people concurrently, I process in small chunks (around 50 requests) and when I finish a chunk, or if I hit a rate limit within the chunk, I move on to another user for a while (typically around 10-15 minutes) before coming back. 因为我的特定应用程序同时处理多个人,我处理小块(大约50个请求),当我完成一个块,或者如果我在块中达到速率限制,我会转移到另一个用户一段时间(通常回来之前约10-15分钟。

I imagine the API limit is per-appid/clientkey, which is why you could follow users on the instagram app despite reaching your limit. 我认为API限制是每appid / clientkey,这就是为什么你可以在Instagram应用程序上关注用户,尽管达到了你的限制。

Note, the API is complaining about requests , not follows. 请注意,API正在抱怨请求 ,而不是以下。 You may be following 50 users but you have made API requests that exceed 5000. With your current code, it will only take 100 page refreshes for you to reach that limit. 您可能关注了50个用户,但您已经发出超过5000的API请求。使用您当前的代码,只需要100次页面刷新即可达到该限制。 Might sound like a lot of refreshes but if you are debugging/developing code then it is plausible to assume that you could exceed the 100 refresh threshold with relative ease. 可能听起来像很多刷新,但如果你正在调试/开发代码,那么假设你可以相对容易地超过100刷新阈值是合理的。

To mitigate this problem, if you are still working/debugging this code then reduce the number of follows from 50 to 1 or 2. Once your code is working then reinstate the previous number of follows. 要缓解此问题,如果您仍在使用/调试此代码,请将后续数量从50减少到1或2.一旦您的代码正常工作,然后恢复以前的数量。 I would recommend you cache the return objects too, for 5 or 10 minutes. 我建议你也要缓存返回对象,持续5或10分钟。 That way you won't need to worry about exceeding the API limits. 这样您就不必担心超出API限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM