Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer could not fetch github

Today, I try to do Laravel install by running composer create-project laravel/laravel=5.1.* myproject --prefer-dist and I get this error:

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.

Why am I unable to fetch from GitHub? This is the first time I am facing this after years of using. Is there any policy change by GitHub?

like image 255
user1995781 Avatar asked Feb 19 '16 03:02

user1995781


3 Answers

The accepted answer of Niels is correct. To use the generated token in composer use the command:

composer config -g github-oauth.github.com YOUR_TOKEN
like image 199
Paweł Napierała Avatar answered Nov 16 '22 21:11

Paweł Napierała


This policy has been active at Github a long time regrettably. It is documented here and you can see your current status at https://api.github.com/rate_limit in the core section.

Also see https://developer.github.com/v3/#rate-limiting:

For unauthenticated requests, the rate limit allows you to make up to 60 requests per hour. Unauthenticated requests are associated with your IP address, and not the user making requests.

There is nothing Composer can do to circumvent that, hence why it throws the verbose error:

Create a GitHub OAuth token to go over the API rate limit

You can do this at https://github.com/settings/tokens, and it needs to be done only once per installation as Composer remembers the token for subsequent requests.

like image 29
Niels Keurentjes Avatar answered Nov 16 '22 21:11

Niels Keurentjes


2022 Update for Composer 2.x

I tried the other solutions listed here and they didn't work for me. Inspecting the verbose output of composer update I found that you can set the github.accesstoken configuration option using git and Composer will use that.

  1. Create a GitHub Personal Access Token and copy the token to your clipboard
  2. Run git config --global github.accesstoken <token>, replacing <token> with the token from above.

You can remove the --global option if you want to set the token specifically for your current project.

like image 14
Simon Hartcher Avatar answered Nov 16 '22 21:11

Simon Hartcher