As the title says, i'm trying to connect to the reddit API, i've created an app (named comment extractor) on my profile, and copy paste the public and secret keys, and use http://localhost:1410/ as redirect URI and about URL. The app is a script, but i tried web app as well with the same result.
The code i'm using is just copy pasted from Hadleys httr demos, but i exchanged the keys for my own (everything done with the latest version of httr, 1.3.1).
library(httr)
# 1. Find OAuth settings for reddit:
# https://github.com/reddit/reddit/wiki/OAuth2
reddit <- oauth_endpoint(
authorize = "https://www.reddit.com/api/v1/authorize",
access = "https://www.reddit.com/api/v1/access_token"
)
# 2. Register an application at https://www.reddit.com/prefs/apps
app <- oauth_app("comment extractor", "rrG5wfgHkm5Kvw", "[secret key]")
# 3b. If get 429 too many requests, the default user_agent is overloaded.
# If you have an application on Reddit then you can pass that using:
token <- oauth2.0_token(
reddit, app,
scope = c("read", "modposts"),
use_basic_auth = TRUE,
config_init = user_agent("reddit_username")
)
The web browser opens, i'm asked to allow or deny the token, and everything seems fine, but it always fails with this message
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params =
user_params, :
Unauthorized (HTTP 401). Failed to get an access token.
I was unsure of what to do with the user agent, i noticed the app asks for developer names so i tried both some random text and using my reddit username there, either way, i always get a 401 error, which seems to mean wrong keys, but they definately aren't.
Any help would be greatly appreciated, i'm somewhat at a loss when i get stopped at the most basic step and don't know what to do next.
I'm having the exact same problem! I have not found a solution yet, but I think I have found where the problem may lie.
The error occurs in the oauth2.0_access_token function and not in the oauth2.0_token function. In the oauth2.0_token function we have set the "use_basic_auth" to TRUE. BUT in the oauth2.0_acces_token function the default for "use_basic_auth" is set to FALSE.
Since the token function seems to call the acces_token function, I have no idea how to change that default... but I hope my insight will bring us a step closer (If you have found the final solution, would you please share this with me?)