我正在构建一个应用程序来获取问题和拉取请求 https://developer.github.com/v3/超过 1K 的 github 存储库,就像这样。
$ 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"
}
该文档说我可以使用最多 5000 个请求验证 https://developer.github.com/v3/#authentication我注册了一个 oauth 并获得了Client ID
and Client Secret
tokens
https://api.github.com/repos/{repo.name}/issues?client_id=...&client_secret=...
但速率限制仅在大约 60 个请求后才会显示。
正如您所观察到的,公共 GitHub API 请求限制为 60 个/小时/ip。这就是您需要身份验证的原因。
有多种方式进行身份验证 https://developer.github.com/v3/auth/当您使用 GitHub API 时。
基本身份验证 https://developer.github.com/v3/auth/#basic-authentication
基本上,您提供用户名和密码。
curl -u your-username "https://api.github.com/repos/user/repo/issues?state=closed"
这将提示您输入密码。
如果您不想使用密码,可以使用个人代币 https://github.com/blog/1509-personal-api-tokens:
curl -u username:token "https://api.github.com/repos/user/repo/issues?state=closed"
使用个人访问令牌
这是我最喜欢的,但请确保不要与其他人共享令牌代码。要生成新令牌,打开这个页面 https://github.com/settings/tokens/new,您将创建令牌。
然后你可以像这样使用它:
curl "https://api.github.com/repos/user/repo/issues?state=closed&access_token=token"
(更换token
网址末尾的片段以及您的令牌代码)
OAuth
如果您想为其他用户实现身份验证,则应该使用 OAuth。这docs https://developer.github.com/v3/oauth/在这个方向上都很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)