Composer 无法获取 github

use*_*781 5 php github composer-php

今天,我尝试通过运行来安装 Laravel,composer create-project laravel/laravel=5.1.* myproject --prefer-dist但出现此错误:

Could not fetch https://api.github.com/repos/laravel/laravel/zipball/716e65268ae123e5bd73e505acf9695c678aff88, please create a GitHub OAuth token to go over the API rate limit
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+MyPC+2016-02-19+0343 to retrieve a token. It will be stored in "C:/Users/MyPC/AppData/Roaming/Composer/auth.json" for future use by Composer.
Run Code Online (Sandbox Code Playgroud)

为什么我无法从 GitHub 获取?这是我使用多年后第一次遇到这种情况。GitHub 是否有任何政策变化?

Sim*_*her 29

Composer 2.x 2022 年更新

我尝试了此处列出的其他解决方案,但它们对我不起作用。检查详细输出,composer update我发现您可以github.accesstoken使用设置配置选项git,Composer 将使用它。

  1. 创建GitHub 个人访问令牌并将令牌复制到剪贴板
  2. 运行git config --global github.accesstoken <token>,替换<token>为上面的令牌。

--global如果您想专门为当前项目设置令牌,您可以删除该选项。

  • 啊,这对我有用,应该是 Composer v2 可接受的答案:) (2认同)

Nie*_*jes 5

遗憾的是,这个政策在 Github 已经活跃了很长时间。据记载这里,你可以看到你目前的状态https://api.github.com/rate_limitcore部分。

另请参阅https://developer.github.com/v3/#rate-limiting

对于未经身份验证的请求,速率限制允许您每小时最多发出 60 个请求。未经身份验证的请求与您的 IP 地址相关联,而不是与发出请求的用户相关联。

Composer 无法避免这种情况,因此它会抛出冗长的错误:

创建 GitHub OAuth 令牌以超过 API 速率限制

您可以在https://github.com/settings/tokens执行此操作,并且每次安装只需执行一次,因为 Composer 会记住后续请求的令牌。


Paw*_*ała 5

尼尔斯接受的答案是正确的。要在 Composer 中使用生成的令牌,请使用以下命令:

composer config -g github-oauth.github.com YOUR_TOKEN
Run Code Online (Sandbox Code Playgroud)

  • 只需从此链接创建新令牌:https://github.com/settings/tokens,然后使用上面的命令来设置令牌。完毕。 (2认同)