使用HTTP标头的Instagram API计数限制 [英] Instagram API count limits using HTTP header
问题描述
根据Instagram,您可以使用随呼叫提供的HTTP标头检查剩余的API限制计数。我对此很陌生,无法找到有关如何使用PHP访问此信息的相关数据。有人可以帮我解释一下吗?
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?
我在Google网上论坛的Instagram API开发人员论坛上发现了以下内容:
I found the following from the Instagram API developers forum on Google Groups:
我们刚刚将其推广到生产;所有API调用现在都有
额外的HTTP标头:
-
X-Ratelimit-Limit
(每小时可能的电话总数) -
X-Ratelimit-Remaining
(此特定令牌或客户ID的剩余电话数)
X-Ratelimit-Limit
(total # of possible calls per hour)X-Ratelimit-Remaining
(how many calls are left for this particular token or client ID)"
推荐答案
如果你正在使用 file_get_contents
发出请求(或任何使用 HTTP包装器的任何内容),特殊变量 $ http_response_header
包含一系列行,其中包含最近请求的HTTP响应头。
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.
也许是这样的:
// 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";
这篇关于使用HTTP标头的Instagram API计数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!