httr github-API callback URL issues
Asked Answered
R

4

16

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

Recommendatory answered 1/11, 2012 at 0:20 Comment(0)
S
13

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.

Simplism answered 22/5, 2014 at 14:55 Comment(3)
Very nice. I had to install and load the httpuv package as well for it to work, but it went very smoothly from the error messages.Staunch
What was the end working script for this? I am having the same issue and this question doesn't have a posted solution. Thanks.Tinaret
For me, the callback URL had to set as "localhost:1410" (don't forget the last backslash).Chippy
E
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.

Egret answered 4/2, 2013 at 22:40 Comment(0)
A
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.

good luck.

Antipyretic answered 15/8, 2015 at 17:24 Comment(0)
T
0

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

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

you should be able to see 'authentication complete'.

Titmouse answered 23/3, 2017 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.