Instagram API count limits using HTTP header

两盒软妹~` 提交于 2019-12-10 09:40:28

问题


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)"

回答1:


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";


来源:https://stackoverflow.com/questions/12144986/instagram-api-count-limits-using-http-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!