我现在也在使用httr v0.2包来使用github api。但我正在努力通过oauth2.0(...)部分,在这个部分中,我进入我的应用程序的浏览器页面,单击“允许”,然后被重定向到回调URL页面。
httr github演示建议使用回调URL作为http://localhost:1410,但当我被重定向到该页面时,谷歌chrome显示它无法连接到该页面,它被重定向到的页面是http://localhost:1410/?error=redirect_uri_mismatch&state=DZNFcm8tnq...so我尝试了一堆其他端口和整体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...这是当我被定向到一个有‘允许’按钮whichIi点击的页面,之后我被重定向到google chrome中无法连接到localhost :1410的页面。
发布于 2014-05-22 22:55:55
您应该将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)您可以使用demo("oauth2-github", package = "httr", ask = FALSE)命令获取它。
发布于 2013-02-05 06:40:24
你是通过web应用来提供这个服务的,还是它是一个扩展/插件?重定向url必须与您在设置github应用程序时指定的回调url来自同一主机。有关详细信息,请参阅here。如果您在扩展中使用API,那么我不会提供太多帮助。当我遇到你的问题时,这就是我要找的。
发布于 2015-08-16 01:24:30
我遇到了完全相同的错误和问题,通过按照演示:http://github.com将主页URL修改为正确的URL解决了问题,因此最终问题不是在回调URL中,而是在主页URL中,您也可以在oauth2.0_token()函数中使用cache=F参数。
祝好运。
https://stackoverflow.com/questions/13169305
复制相似问题