authorization code for Github API used in R

前端 未结 2 1802
有刺的猬
有刺的猬 2020-12-28 10:24

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

相关标签:
2条回答
  • 2020-12-28 10:59

    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")`

    0 讨论(0)
  • 2020-12-28 11:16

    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.

    0 讨论(0)
提交回复
热议问题