h.l*_*l.m 15 r github github-api httr
我现在正在使用httr
v0.2包来使用github api.但是我很难超越oauth2.0(...)
我进入应用程序浏览器页面的部分,单击"允许"然后重定向到回调URL页面.
httr github演示建议使用回调URL,http://localhost:1410
但当我被重定向到该页面时,谷歌浏览器表明它无法连接到该页面,而它正在被重定向的页面是http://localhost:1410/?error=redirect_uri_mismatch&state=DZNFcm8tnq
...所以我尝试了一堆其他端口和整体URL没有成功......
什么是另一个回调URL和URL可以工作?
下面是我使用的代码
require(httr)
## Loading required package: httr
github.app <- oauth_app("github","xxxxx", "xxxxxxxxxxxxxxx")
github.urls <- oauth_endpoint(NULL, "authorize", "access_token",base_url = "https://github.com/login/oauth")
github.token <- oauth2.0_token(github.urls,github.app)
## Loading required package: Rook
## Loading required package: tools
## Loading required package: brew
## starting httpd help server ... done
## Waiting for authentication in browser...
Run Code Online (Sandbox Code Playgroud)
这是当我被定向到一个页面,其中有一个'允许'按钮,点击之后,我被重定向到google chrome中无法连接到localhost的页面:1410
Art*_*sov 12
您应该将httr
软件包更新到最新版本(现在它是0.3 - 在CRAN中可用).我从httr
(版本0.3)演示中找到了相关示例:
library(httr)
# 1. Find OAuth settings for github:
# http://developer.github.com/v3/oauth/
oauth_endpoints("github")
# 2. Register an application at https://github.com/settings/applications
# Insert your values below - if secret is omitted, it will look it up in
# the GITHUB_CONSUMER_SECRET environmental variable.
#
# Use http://localhost:1410 as the callback url
myapp <- oauth_app("github", "56b637a5baffac62cad9")
# 3. Get OAuth credentials
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
# 4. Use API
req <- GET("https://api.github.com/rate_limit", config(token = github_token))
stop_for_status(req)
content(req)
Run Code Online (Sandbox Code Playgroud)
你可以通过demo("oauth2-github", package = "httr", ask = FALSE)
命令获得它.