2016-12-01 60 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標題。

您可以通過檢查響應正文來確認確切的問題,其中將包含確切錯誤和推理的詳細信息。

相關問題