httr github-API callback URL issues
github, github-api, httr, r
Solution
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.
Problem
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