Instagram API count limits using HTTP header

旧巷老猫 提交于 2019-12-05 21:02:42

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