httr github-API回调URL问题

h.l*_*l.m 15 r github github-api httr

我现在正在使用httrv0.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)命令获得它.

  • 非常好.我不得不安装并加载httpuv包以使其正常工作,但它从错误消息中顺利进行. (2认同)

Faj*_*hos 0

您是通过网络应用程序提供此服务还是扩展/插件?重定向 url 必须与您在设置 github 应用程序时指定的回调 url 来自同一主机。请参阅此处了解更多信息。如果您在扩展中使用 API,那么我不会提供太多帮助。当我遇到你的问题时,这就是我正在寻找的。