2016-12-01 61 views
0

我想列出GitHub存储库。我可以在浏览器中显示JSON,但是当我尝试加载一个API页面,我得到一个403错误:403使用存储库搜索API时禁止使用

Warning: file_get_contents(https://api.github.com/search/repositories?q=user:<username>): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

我的功能如下:

public function repoListAction() 
{ 
    $repositories = json_decode(file_get_contents('https://api.github.com/search/repositories?q=user:<put your username here>'), true); 

    return $this->render('full/repolist.html.twig', array(
     'repositories' => $repositories, 
    )); 
} 

回答

1

GitHub's API documentation列出了几种原因一个403响应码。您可能已达到Github对未经身份验证的查询的费率限制。您可以通过检查X-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Reset标题来确认。您的请求中也可能缺少User-Agent标题。

您可以通过检查响应正文来确认确切的问题,其中将包含确切错误和推理的详细信息。

相关问题