Reddit 获取 api Oauth 令牌 javascript/react js

Reddit Getting the api Oauth token javascript/react js

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

这是我在 Postman 中使用的 header 和 POST body。

//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

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

grant_type=authorization_code&code=....

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