【问题标题】:Reddit Getting the api Oauth token javascript/react jsReddit 获取 api Oauth 令牌 javascript/react js
【发布时间】:2021-01-08 12:07:05
【问题描述】:

我从 reddit OAuth API 获得了 OAuth 代码,但之后尝试获取令牌时出现 401 授权错误。我正在使用邮递员将帖子请求发送到https://www.reddit.com/api/v1/access_token

这是我在 Postman 中使用的标题和 POST 正文。

//Headers
Authorization:Basic Base.Encode64(clientid:secret)
Content-Type:application/x-www-form-urlencoded
//client id and secret are those which I got by creating the app in reddit
//Body
{
    "grant_type":"authorization_code",
    "code":"authcode which I got from the get request before",
    "redirect_uri":"http://localhost:3000"
}
//I tried sending these through query string as well

【问题讨论】:

    标签: javascript reactjs postman reddit reddit-access-token


    【解决方案1】:

    body 看起来像 json 而不是表单数据。参数必须以类似这样的形式数据格式发送。将 postman 中的 body 类型更改为 x-www-form-urlencoded

    grant_type=authorization_code&code=....
    

    我在 Pathfix 工作,如果您想尝试一下,我们的无服务器平台上有 Reddit。

    【讨论】:

    • 谢谢..仍然收到相同的未经授权的 401 错误。其他的都好吗??我对授权标头语法有疑问
    • 标题似乎正确。我们使用完全相同的格式,而且效果很好。此外,我确定重定向 url 与检索代码时发送的原始 URL 匹配吗?同样在邮递员中,您使用的是授权选项卡还是标题选项卡?您应该使用授权选项卡
    • 我正在使用标题选项卡...我应该在授权选项卡中使用哪个字段?
    • 我选择了基本身份验证,它给了我 invalid_grant 错误
    • 我仍然坚持。你能帮我拿到令牌吗?
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2018-09-18
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 2017-09-16
    相关资源
    最近更新 更多