热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

httrgithub-API回调URL问题。-httrgithub-APIcallbackURLissues

Iamusingthehttrv0.2packagetousethegithubapiaswellnow.ButIamstrugglingtogetpast

I am using the httr v0.2 package to use the github api as well now. But I am struggling to get past the oauth2.0(...) part in which I get to the browser page for my app, click on 'Allow' and then get redirected to the callback URL page.

我现在也在使用httr v0.2包来使用github api。但是,我正在努力克服oauth2.0(…)的部分,我在其中找到了我的应用程序的浏览器页面,点击“允许”,然后被重定向到回调URL页面。

The httr github demo suggests using the callback URL as http://localhost:1410 but when I get redirected to that page, google chrome suggests that it could not connect to the page and the page it is getting re-directed to is http://localhost:1410/?error=redirect_uri_mismatch&state=DZNFcm8tnq...so I tried a bunch of other ports and overall URLS to no success...

httr github演示程序建议使用回调URL作为http://localhost:1410,但是当我被重定向到该页面时,谷歌chrome建议它不能连接到该页面,它正在被重定向到的页面是http://localhost:1410/?error=redirect_uri_mismatch&state= dznfcm8q…所以我尝试了一些其他的端口和url,但没有成功。

What would be another callback URL and URL that would work?

另一个回调URL和URL是什么?

below is the code I used

下面是我使用的代码。

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...

which is when I get directed to a page that has the 'Allow' button whichIi click after which I get redirected to the page in google chrome that cannot connect to localhost :1410

当我被指向一个有“允许”按钮的页面时,点击之后,我就会被重定向到无法连接到localhost:1410的谷歌chrome中的页面

4 个解决方案

#1


12  

You should update httr package to latest version (now it's 0.3 - available in CRAN). I found the relevant example from httr (version 0.3) demos:

您应该将httr包更新到最新版本(现在在CRAN中可以使用0.3)。我从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)

You can get it with demo("oauth2-github", package = "httr", ask = FALSE) command.

您可以使用demo(“oauth2-github”,package =“httr”,ask = FALSE)命令获得它。

#2


0  

Are you serving this from a web app or is it an extension/plugin? The redirect url has to be from the same host as the callback url you specified when you set up the github application. See here for more. If you are using the API in an extension then I won't be of much help. That's what I was looking for when I came across your question.

你是在网络应用上提供这个还是扩展/插件?重定向url必须来自与设置github应用程序时指定的回调url相同的主机。在这里看到的。如果您正在扩展中使用API,那么我将不会提供太多帮助。当我遇到你的问题时,这就是我要找的。

#3


0  

I had the same error and problem exactly and the problem was solved by modifying the Homepage URL to the correct one as per the demo : http://github.com so eventually the problem was not in the callback URL it was in the Homepage URL, you might also use the cache=F argument in the oauth2.0_token() function.

我有完全相同的错误和问题,解决了这个问题通过修改主页URL重定向到正确的页面按照演示:http://github.com最终回调URL的问题不是在主页URL,您也可以使用缓存= F参数在oauth2.0_token()函数。

good luck.

祝你好运。

#4


0  

I had the same error. But after I installed httpuv package it worked fine. Once you install httpuv package, upon running this code,

我犯了同样的错误。但是在我安装了httpuv包之后,它工作得很好。一旦安装了httpuv包,运行这段代码后,

github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)

github_token <- oauth2.0_token(oauth_endpoints(“github”),myapp)

you should be able to see 'authentication complete'.

您应该能够看到“身份验证完成”。


推荐阅读
author-avatar
popou
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有