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

api, instagram, php

Solution

Note, the API is complaining about requests, not follows. 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. 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.

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. I would recommend you cache the return objects too, for 5 or 10 minutes. That way you won't need to worry about exceeding the API limits.

Problem

I want to follow a list of user ids in instagram. 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) The developer documentation says: "You are limited to 5000 requests per hour per access_token or client_id overall." but when I get this error, my code hardly followed 50 user ids! 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! 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 :)

Original source