Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github API: Fetch issues with exceeds rate limit prematurely

I am building an app that fetches the issues and pull requests of over 1K github repos, like this.

$ curl -i "https://api.github.com/repos/user/repo/issues?state=closed"

My problem is that, after the initial 60 iterations I get a rate limit error:

{
    "message": "API rate limit exceeded for xxx.xxx.xxx.xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
    "documentation_url": "https://developer.github.com/v3/#rate-limiting"
}

The document says I can make upto 5000 requests using Authentication Which I registered an oauth for and obtained Client ID and Client Secret tokens

https://api.github.com/repos/{repo.name}/issues?client_id=...&client_secret=...

Still the rate limit shows up only after about 60 requests.

like image 560
arbi-g11324115 Avatar asked Nov 11 '15 16:11

arbi-g11324115


People also ask

How do I fix the API rate limit exceeded GitHub?

Solution: Add authentication details or the client ID and secret (generated when you register your application on GitHub). Important to note to only do this for server-2-server communication. Otherwise, your client secret can be exposed to the user. Even if you include the credentials, the rate limit is 5000 per hour.

How do I fix the API rate limit exceeded?

Resolve a 403 error: Project rate limit exceeded To fix this error, try any of the following: Raise the per-user quota in the Google Cloud project. For more information, request a quota increase. Batch requests to make fewer API calls.

What does it mean when it says API rate limit exceeded?

If API requests exceed the maximum rate per second, you receive a "Rate Exceeded" error, and API calls are then throttled. Some API calls can be made dozens of times per second, while others are limited to a few allowed calls per second.

What is the rate limit of GitHub API?

Requests from GitHub Actions When using GITHUB_TOKEN , the rate limit is 1,000 requests per hour per repository. For requests to resources that belong to an enterprise account on GitHub.com, GitHub Enterprise Cloud's rate limit applies, and the limit is 15,000 requests per hour per repository.


1 Answers

The public GitHub API requests are limited to 60 / hour / ip, like you observed. That's why you need authentication.

There are multiple ways to get authenticated when you use the GitHub APIs.

Basic authentication

Basically, you provide the username and the password.

curl -u your-username "https://api.github.com/repos/user/repo/issues?state=closed"

This will prompt you for entering the password.

If you dont want to use the password, you can use a personal token:

curl -u username:token "https://api.github.com/repos/user/repo/issues?state=closed"

Using personal access tokens

This is my favorite, but make sure you don't share the token code with others. To generate a new token, open this page, and you will create the token.

Then you can use it like this:

curl "https://api.github.com/repos/user/repo/issues?state=closed&access_token=token"

(replace the token snippet at the end of the url with your token code)

OAuth

If you want to implement authentication for other users, you should use OAuth. The docs are good in this direction.

like image 156
Ionică Bizău Avatar answered Oct 13 '22 00:10

Ionică Bizău