我想列出 GitHub 存储库。我可以在浏览器中显示 JSON,但是当我尝试加载 API 页面时,出现 403 错误:
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,
));
}