The authorization code for the Github API used in R

I am trying to access the API for information on http://github.com . I created in the application on github (in the developer application) for this URL and tried to access through R using the httr libraries. Below is the code

library(httr) oauth_endpoints("github") myapp <- oauth_app("github",key = "#####################",secret = "########################" ) 

(the key was replaced by the client identifier, and the secret was replaced by secred id)

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

This led me to the following

Use local file to cache OAuth access credentials between R sessions? 1: Yes 2: No

I chose 2 (as I tried option 1 before), 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 the authorization code Can someone tell me what the authorization code is?

+5
source share
2 answers

An authorization code is the code that github delivers after the correct OAuth 2.0 pitch (to use the Hadley Wickham term). The easiest way to do this is to use httpuv ( install.packages("httpuv") ). In this case, the local web server is installed on port 1410 and provided that you have correctly configured the github application (with redirection to http: // localhost: 1410 ).

If you do not have httpuv, then the httr OAuth 2.0 function uses out-of-band authentication by default. This requires that GitHub be redirected to urn: ietf: wg: oauth: 2.0: oob & response_type = cod, which must display the authorization code in the browser so that it can be copied and pasted. However, you almost certainly got something different, like your redirect url, and therefore github complains that the redirect URI does not match. I'm not sure if github can be configured to allow oob redirection (but I just tried and that doesn't seem to).

The only reasons for not using httpuv are if you use R on a machine that does not allow you to configure the server on port 1410, or if you use R on a remote computer through an RStudio Server or SSH session. In the latter case, the web server will be configured on the remote computer, but your browser will try to connect to port 1410 on your local computer. You could get around this by forwarding the SSH port from port 1410 on your local machine to port 1410 on the remote machine.

Please note that the demo code https://github.com/hadley/httr/blob/master/demo/oauth2-github.r , unlike the current version of the CRAN version of oauth2-github, contains a secret for the Hadley application, so you can run the demo since without pre-setting your application.

+8
source

Here is what worked for me:

Install the HTTPUV package from https://github.com/rstudio/httpuv

And maybe set your current user \\R\library permission to run devtools :: install_github ("rstudio / httpuv") `

+1
source

All Articles