【发布时间】:2018-02-20 05:20:11
【问题描述】:
正如标题所说,我正在尝试连接到 reddit API,我在我的个人资料上创建了一个应用程序(名为评论提取器),并复制粘贴公钥和密钥,并使用 http://localhost:1410/ 作为重定向URI 和关于 URL。该应用程序是一个脚本,但我也尝试了 Web 应用程序,结果相同。
我使用的代码只是从 Hadleys httr 演示中复制粘贴,但我用自己的密钥交换了密钥(一切都使用最新版本的 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")
)
网络浏览器打开,我被要求允许或拒绝令牌,一切似乎都很好,但总是失败并显示此消息
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.
我不确定如何处理用户代理,我注意到该应用程序要求提供开发人员姓名,所以我尝试了一些随机文本并在那里使用我的 reddit 用户名,无论哪种方式,我总是收到 401 错误,这似乎意味着错误的键,但它们肯定不是。
任何帮助将不胜感激,当我在最基本的步骤上停下来不知道下一步该怎么做时,我有点不知所措。
【问题讨论】: