I am trying Access the API to get information on http://github.com. I created in application in github (in developer application) for this URL and try to access thru R using httr libraries. The following is the code
library(httr)
oauth_endpoints("github")
myapp <- oauth_app("github",key = "#####################",secret = "########################" )
(key was replaced with client id and secret was replaced with secred id)
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
This prompted me the following
Use a local file to cache OAuth access credentials between R sessions? 1: Yes 2: No
I selected 2 (as i tried option 1 earlier) then the following are displayed
httpuv not installed, defaulting to out-of-band authentication
Please point your browser to the following url:
https://github.com/login/oauth/authorize?client_id=72939e1b6d499f4f1894&scope=&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code
Enter authorization code Can any one tell me what the authorization code is?
The authorisation code is the code that github supplies after a correct OAuth 2.0 'dance' (to use Hadley Wickham's term). The easiest way of doing this is to use httpuv (install.packages("httpuv")
). With that installed, a local webserver is setup on port 1410 and provided you've setup your github application appropriately (with a redirect to http://localhost:1410).
If you don't have httpuv installed, then httr's OAuth 2.0 function defaults to out of band authorisation. This asks GitHub to redirect to urn:ietf:wg:oauth:2.0:oob&response_type=cod which should display the authorisation code within the browser so that it can be copied and pasted. However, you've almost certainly got something different set as your redirect URL and so github complains that there is a redirect URI mismatch. I'm not sure whether github can be configured to allow the oob redirect (but I've just tried and it doesn't seem to).
The only reasons not to use httpuv are if you are using R on a machine that won't let you set up a server on port 1410 or if you are using R on a remote machine via RStudio Server or an SSH session. In the latter case, the webserver will be setup on the remote machine, but your browser will be trying to connect to port 1410 on your local machine. You could potentially get around this by doing SSH port forwarding from port 1410 on your local machine to port 1410 on the remote machine.
Note also that the demo code at https://github.com/hadley/httr/blob/master/demo/oauth2-github.r unlike the current CRAN version of the oauth2-github demo includes the secret for Hadley's application so you can run the demo as is without setting up your own application first.
Here's what worked for me:
Install package HTTPUV from https://github.com/rstudio/httpuv
And maybe set your \\R\library
permission for the current user for running devtools::install_github("rstudio/httpuv")`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With