Github API:提前超过速率限制提取问题 [英] Github API: Fetch issues with exceeds rate limit prematurely

查看:4819
本文介绍了Github API:提前超过速率限制提取问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,获取超过1K github回购的问题和请求,就像这个。

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

我的问题是,在最初的60次迭代之后,我得到一个速率限制错误:

  {
message:xxx.xxx.xxx.xxx超出API限制。(但这里是好消息:验证过的请求会获得更高的速率限制,请查看文档以获取更多详细信息。),
documentation_url:https://developer.github.com/v3/#rate-limiting
}

该文件说我可以使用身份验证我为其注册了一个oauth并获得了客户端ID 客户端秘密令牌



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



然而,只有约60次请求才会显示速率限制。

解决方案

公共GitHub API请求限于60 /小时/这就是为什么你需要认证。





基本身份验证



基本上,您提供了用户名和密码。

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

这会提示您输入密码。



如果你没有想要使用密码,您可以使用个人令牌

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



使用个人存取令牌



这是我的最喜欢的,但确保你不要shar e与其他令牌代码。要生成新令牌,请打开此页面,然后创建令牌。



然后你可以像这样使用它:

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

(使用您的令牌代码替换URL末尾的标记代码片段)


$ b

OAuth



如果您想为其他用户实施身份验证,则应使用OAuth。 文档在这方面很好。


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.

解决方案

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.

这篇关于Github API:提前超过速率限制提取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆