gpt4 book ai didi

api - Reddit API Oauth2 "user required"

转载 作者:行者123 更新时间:2023-12-02 01:32:04 35 4
gpt4 key购买 nike

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

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

正文是这样的:

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": "*"}

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

--5e65dP1dI_1vgLbqvi7zRB6cnU

然后我尝试在 https://oauth.reddit.com/api/v1/me 上执行 GET 请求使用这些 header :

   {
User-Agent: (testUWP client by /u/bored_reddit_user)
Authorization: bearer --5e65dP1dI_1vgLbqvi7zRB6cnU
}

我得到了这些 header ,状态码为 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很好地概述了 reddit 的 OAuth2 实现和不同的 grant_types 以及它们适用于什么情况。 This page有更多信息。我怀疑 reddit 不希望您将客户端密码存储在您安装在用户设备上的应用程序中,因为您无法保证它的安全,并且用户可以找出您的 CLIENT_ID。

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

关于api - Reddit API Oauth2 "user required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33577188/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com