Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httr github-API callback URL issues

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.

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

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

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

like image 827
h.l.m Avatar asked Nov 01 '12 00:11

h.l.m


1 Answers

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:

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.

like image 182
Artem Klevtsov Avatar answered Oct 15 '22 15:10

Artem Klevtsov