Mark Mark - 1 year ago 102
R Question

R - curl Github API to access private repos

All I'm trying to do is read all the repos and issues in my organizations private repos. I can from my Windows 7


curl -u "user:pass"

and I get back all of my repositories. I can pipe this to a file:

curl -u "user:pass" > "C:\Users\Location\file.txt"

and this saves the JSON output. I can replicate this in R but in what seems like a terrible way.

fullRepos = system('curl -s -u "user:pass" -G',
intern=T,show.output.on.console = F)

This captures the output (
intern = T
) and the
gets rid of the progress bars so I can collapse the lines and turn it into a data frame. This gets back all the repositories, public and private.

I tried using
to do the same thing but the code below only provides the public repositories. The
is because otherwise it the API rejects my call.

RCurl::getURL(url="",userpwd ="user:pass",
httpheader = c('User-Agent' = "A user agent"))

I also tried
and it also only provides the public repositories.


What am I doing wrong with
? I'd rather have a workflow that doesn't make a system command and then paste the lines together.

Answer Source

We can use the authenticate() helper function in httr to build the authentication header for us w/o having to manually create it. Also, verbose() can be used to debug HTTP issues:

          httr::authenticate("user", "pass"), 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download