11

I am trying to create an OAuth token from the command line using the instructions here. I am able to use curl from the command line, and get the correct response

curl -u 'username:pwd' -d '{"scopes":["user", "gist"]}' \
  https://api.github.com/authorizations

Now, I want to replicate the same in R using RCurl or httr. Here is what I tried, but both commands return an error. Can anyone point out what I am doing wrong here?

httr::POST(
  'https://api.github.com/authorizations',
  authenticate('username', 'pwd'),
  body = list(scopes = list("user", "gist"))
)

RCurl::postForm(
  uri = 'https://api.github.com/authorizations',
  .opts = list(
    postFields = '{"scopes": ["user", "gist"]}',
    userpwd = 'username:pwd'
  )
)
vrajs5
  • 4,066
  • 1
  • 27
  • 44
Ramnath
  • 54,439
  • 16
  • 125
  • 152

1 Answers1

0

The question is ages old, but maybe still helpfull to some: The problem should be that the opts arguments are passed in the wrong way (lacking a curlOptions function call). The following worked for me in a different context:

result <- getURL(url,.opts=curlOptions(postfields=postFields))

(and yes, as far as I know you can use getURL function for POST requests).

Valentin
  • 641
  • 8
  • 12