javascriptreactjspostmanredditreddit-access-token

Reddit Getting the api Oauth token javascript/react js


I got the OAuth code from the reddit OAuth API but I am getting 401 authorization error when trying to get the token after that. I am using postman for sending the post request to https://www.reddit.com/api/v1/access_token

Here is my header and POST body which I am using in Postman.

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

Solution

  • The body looks like json and not form data. The parameters would have to be sent form data format something like this. Change the body type in postman to x-www-form-urlencoded

    grant_type=authorization_code&code=....
    

    I work at Pathfix and we have Reddit on our serverless platform if you'd like to give it a shot.