Github API:过早超出速率限制的获取问题
Github API: Fetch issues with exceeds rate limit prematurely
我正在构建一个应用程序来获取超过 1K github 回购的 issues and pull requests,就像这样。
$ curl -i "https://api.github.com/repos/user/repo/issues?state=closed"
我的问题是,在最初的 60 次迭代之后,我得到了一个速率限制错误:
{
"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"
}
文档说我最多可以使用 Authentication 发出 5000 个请求,我为此注册了一个 oauth 并获得了 Client ID
和 Client Secret
令牌
https://api.github.com/repos/{repo.name}/issues?client_id=...&client_secret=...
仍然只有在大约 60 个请求后才会出现速率限制。
public GitHub API 请求限制为 60 / 小时 / ip,如您观察到的那样。这就是您需要身份验证的原因。
使用GitHubAPI时有multiple ways to get authenticated。
Basic authentication
基本上,您提供用户名和密码。
curl -u your-username "https://api.github.com/repos/user/repo/issues?state=closed"
这将提示您输入密码。
如果不想使用密码,可以使用personal token:
curl -u username:token "https://api.github.com/repos/user/repo/issues?state=closed"
使用个人访问令牌
这是我最喜欢的,但请确保您不与他人共享令牌代码。要生成新令牌,open this page,您将创建令牌。
那么你可以这样使用它:
curl "https://api.github.com/repos/user/repo/issues?state=closed&access_token=token"
(用您的令牌代码替换 url 末尾的 token
片段)
OAuth
如果你想为其他用户实现认证,你应该使用OAuth。 docs这方面不错
我正在构建一个应用程序来获取超过 1K github 回购的 issues and pull requests,就像这样。
$ curl -i "https://api.github.com/repos/user/repo/issues?state=closed"
我的问题是,在最初的 60 次迭代之后,我得到了一个速率限制错误:
{
"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"
}
文档说我最多可以使用 Authentication 发出 5000 个请求,我为此注册了一个 oauth 并获得了 Client ID
和 Client Secret
令牌
https://api.github.com/repos/{repo.name}/issues?client_id=...&client_secret=...
仍然只有在大约 60 个请求后才会出现速率限制。
public GitHub API 请求限制为 60 / 小时 / ip,如您观察到的那样。这就是您需要身份验证的原因。
使用GitHubAPI时有multiple ways to get authenticated。
Basic authentication
基本上,您提供用户名和密码。
curl -u your-username "https://api.github.com/repos/user/repo/issues?state=closed"
这将提示您输入密码。
如果不想使用密码,可以使用personal token:
curl -u username:token "https://api.github.com/repos/user/repo/issues?state=closed"
使用个人访问令牌
这是我最喜欢的,但请确保您不与他人共享令牌代码。要生成新令牌,open this page,您将创建令牌。
那么你可以这样使用它:
curl "https://api.github.com/repos/user/repo/issues?state=closed&access_token=token"
(用您的令牌代码替换 url 末尾的 token
片段)
OAuth
如果你想为其他用户实现认证,你应该使用OAuth。 docs这方面不错