Reputation: 739
I've been trying to authenticate with Reddit from R using RCurl based on this example from Reddit's github:
curl -X POST -d 'grant_type=password&username=reddit_bot&password=snoo' --user 'p-jcoLKBynTLew:gko_LXELoV07ZBNUXrvWZfzE3aI' https://ssl.reddit.com/api/v1/access_token
I've tried to convert it to an RCurl command like so:
postForm("https://ssl.reddit.com/api/v1/access_token?grant_type=password",
username = "MyUserName",
password = "MyPassword",
.opts = list(userpwd = "MyClientid:MySecret")
)
But I get an error: Error: Unauthorized
I'm not sure what I'm doing really with the conversion of the curl command to Rcurl. Thanks for any help you could provide!
Upvotes: 4
Views: 301
Reputation: 103928
Try this httr code:
library(httr)
POST("https://ssl.reddit.com/api/v1/access_token",
body = list(
grant_type = "password",
username = "MyUserName",
password = "MyPassword"
),
encode = "form",
authenticate("p-jcoLKBynTLew", "gko_LXELoV07ZBNUXrvWZfzE3aI")
)
Upvotes: 3