I am trying to use reddit api to send private message on behalf of the user. But I am not being able to complete the Oauth2 authorization to get an access token.
I am following the guide here: https://github.com/reddit-archive/reddit/wiki/OAuth2
I have created a reddit developer app and I am following the code flow steps. After getting the code
from the authorization
endpoint, I make the following request to exchange the code for an access token.
curl --location --request POST 'https://www.reddit.com/api/v1/access_token' \
--header 'User-Agent: *******' \
--header 'Authorization: Basic *******' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=*******' \
--data-urlencode 'redirect_uri=http://localhost:1410/'
But instead of the access token, I get the following error:
{
"message": "Bad Request",
"error": 400
}
Any ideas what I am doing wrong?
It has been a few months since the question was posted. I was finally able to solve it.
Here is what I was doing wrong.
After the user logs in and gives the app the necessary permission, you are redirected to a URL that contains the code
parameter. I noticed that the codes have #_
at the end. I just removed the trailing #_
and made the same request in my original question and it worked.