Get the api oath access token from reddit api

723 Views Asked by At

I got the code successfully from the reddit oauth api but I am getting invalid grant(Before I was getting 401 unauthorized on sending data as json) error when trying to get the access 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 form data which I am using in postman. I am sending my client id and secret in authorization tab(tried in sending header) from postman and using x-www-form-urlencoded to send grant type, code and redirect uri(tried sending them as a form data and json as well). In headers my content type is x-www-form-urlencoded. Please help in getting the token if someone have used reddit api.

//Headers
Content-Type:application/x-www-form-urlencoded
//authorization
Authorization:Basic Base.Encode64(clientid:secret)
//client id and secret are those which I got by creating the app in reddit
//x-www-form-urlencoded.
{
    "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
1

There are 1 best solutions below

0
On

Your token expires after 3600 minutes if I am not mistaken