Github API: Fetch issues with exceeds rate limit prematurely

匆匆过客 提交于 2019-12-22 08:08:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/33655700/github-api-fetch-issues-with-exceeds-rate-limit-prematurely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!