Reddit API Oauth2 "user required"

Reddit API Oauth2 "user required"

我正在尝试让安装的应用程序在 Reddit 的 api 上与 Oauth2 一起工作。我正在使用 Windows 运行时 api 的 httpclient 发出请求,并使用 webauthenticationbroker 获取代码来执行 GET 请求以接收令牌。我使用这个请求了一个令牌:

https://www.reddit.com/api/v1/authorize?client_id=" + client_id + "&response_type=code&state=" + "testing" + "&redirect_uri=http://abcd.com&duration=" + "permanent" + "&scope=" + "vote,identity"

并得到了一个代码,所以我在上面使用了 POST(内容类型为:application/x-www-form-urlencoded):

https://www.reddit.com/api/v1/access_token

body 是这样的:

grant_type=https://oauth.reddit.com/grants/installed_client&\
device_id="+id + "&code=" + code    

(code和id为第一步收到的code,id为生成的UUID)

然后我得到了这样的回复:

{"access_token": "--5e65dP1dI_1vgLbqvi7zRB6cnU", "token_type": "bearer", "expires_in": 3600, "scope": "*"}

所以我提取了令牌并得到了这个:

--5e65dP1dI_1vgLbqvi7zRB6cnU

然后我尝试使用这些 headers:

https://oauth.reddit.com/api/v1/me 上执行 GET 请求
   {
  User-Agent: (testUWP client by /u/bored_reddit_user)
  Authorization: bearer --5e65dP1dI_1vgLbqvi7zRB6cnU
}                    

我收到了这些 headers 返回状态代码 403 原因短语禁止:

{
  Connection: keep-alive
  Server: cloudflare-nginx
  Strict-Transport-Security: max-age=15552000; includeSubDomains; preload
  Transfer-Encoding: chunked
  cache-control: max-age=0, must-revalidate
  x-ua-compatible: IE=edge
  CF-RAY: 23f5127a6a2911a1-SJC
  Date: Tue, 03 Nov 2015 03:42:58 GMT
  x-frame-options: SAMEORIGIN
  access-control-allow-origin: *
  X-Moose: majestic
  x-reddit-tracking: https://pixel.redditmedia.com/pixel/of_destiny.png?v=BZoi0ikdGrSYn9U9xM6GWeYcRRb0W50fSQuGYb1Q8Oe7E5WVB6qTA4hRqlx9vDfpLOKzpE3Z5Wo%3D
  x-content-type-options: nosniff
  x-xss-protection: 1; mode=block
  access-control-expose-headers: X-Reddit-Tracking, X-Moose
}{
  Content-Type: application/json; charset=UTF-8
}

和此内容:

{"explanation": "Please log in to do that.", "reason": "USER_REQUIRED"}    

我不知道我做错了什么,有人能帮我吗?

This wiki page on the reddit github gives a pretty good overview of reddit's implementation of OAuth2 and the different grant_types and what circumstances they are appropriate for. This page 有更多信息。我怀疑 reddit 不希望您将客户端机密存储在您安装在用户设备上的应用程序中,因为您无法保证它的安全,并且用户可以找出您的 CLIENT_ID.

很高兴我的评论能为您指明正确的方向,如果您能接受这个答案,我将不胜感激。