3

According to Instagram you can check API limit count remaining using the HTTP headers that they supply with the call. I am quite new to this and am unable to find relevant data on how to access this information with PHP. Could anyone please clarify this for me?

I found the following from the Instagram API developers forum on Google Groups:

"We just rolled this out to production; all API calls now have the additional HTTP headers:

  • X-Ratelimit-Limit (total # of possible calls per hour)
  • X-Ratelimit-Remaining (how many calls are left for this particular token or client ID)"
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
muhamin
  • 185
  • 1
  • 8
  • 2
    `u`? please... if you're in such a rush that you can't afford the extra 0.01 seconds it takes to add in the `yo`, then perhaps you should try somewhere else. – Marc B Aug 27 '12 at 15:54
  • ^^ sorry its a bad bad, habit i picked up from chatting , wouldn't happen again :D – muhamin Sep 13 '12 at 03:35

1 Answers1

2

If you're using file_get_contents to make the request (or anything that uses the HTTP wrapper for that matter), the special variable $http_response_header contains an array of lines with the HTTP response headers of the most recent request.

Maybe something like this:

// Make your API request here
...
file_get_contents('http://example.com', false, $context);

// Check HTTP response headers
foreach ($http_response_header as $line) {
    if(preg_match('!X-Ratelimit-Remaining: ([0-9]+)!i', $line, $matches)) {
        $remaining = $matches[1];
        break;
    }
}

// Do something based on the number of remaining attempts
echo "Remaining attempts: $remaining";
quietmint
  • 13,885
  • 6
  • 48
  • 73
  • ^^ yes that dose work just tried and where i was using curl post and used var_dump(get_headers('url that i used to make the call',0)) and i was able to see the ratelimit of overall api calls which they have set ass 5000 , i thought they would supply rate limitation details for relationship modifications too, which they have as 160 modification for an hour , which is BS :D hehe, anyways thanks for the help. marked as answerd. – muhamin Aug 27 '12 at 15:51