Java - 授权GitHub的应用程序

时间:2016-06-06 10:03:25

标签: java api github token authorize

我正在开发一个Java应用程序,它使用GitHub API来下载用户存储库的Zips,但每次执行它时,它都超过了速率限制。如何授权我的Java应用程序每小时达到5000个请求?

  • 我不想使用其他库,只需要纯GitHub API
  • 我有一个可以用来授权的令牌

2 个答案:

答案 0 :(得分:1)

来自https://developer.github.com/v3/

  

增加OAuth应用程序的未经身份验证的速率限制

     

如果您的OAuth应用程序需要使用a进行未经身份验证的调用   更高的费率限制,您可以传递您的应用程序的客户端ID和密码   查询字符串的一部分。

     

curl -i   'https://api.github.com/users/whatever?client_id=xxxx&client_secret=yyyy'

答案 1 :(得分:0)

来自https://developer.github.com/v3/

一旦有OAUTH令牌,有两种方法

  
      
  1. OAuth2令牌(在标头中发送)
  2.         

    curl -H"授权:令牌OAUTH-TOKEN" https://api.github.com   OAuth2令牌(作为参数发送)

         
        
    1. curl https://api.github.com/?access_token=OAUTH-TOKEN
    2.   

e.g。卷曲https://api.github.com/rate_limit?access_token=xxxxxxxxxxxxx

获取OAUTH(访问)令牌参考 - https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization

方法1

使用您的用户ID和密码(用于在网上登录)

curl -X POST https://api.github.com/authorizations -d' {"范围":[" public_repo"],"注意":&# 34;管理脚本"}' -u:

方法2

使用您的应用程序的客户端ID和密码

curl -X POST https://api.github.com/authorizations -d' {"范围":[" public_repo"],"注意":&# 34;管理脚本"," client_id":""," client_secret":""}'

方法3

curl -X PUT https://api.github.com/authorizations/clients/ -d' {"范围":[" public_repo"],"注意":&# 34;管理脚本"," client_secret":""}'

在任何上述调用的响应中,您将获得一个值 "令牌":" abcdefgh12345678",

这是OAUTH或访问令牌。保留此令牌的副本。

您也应该能够使用网络https://github.com/blog/1509-personal-api-tokens

生成令牌

由于我们已经获得了只能访问公共仓库的此令牌,因此将其用于获取TPS应该是安全的。

相关问题