1

Initially i'm getting access token for reddit api by using payload={'grant_type': 'client_credentials', 'duration': 'permanent'} and this gives me access_token as well as refresh token and by using this refresh token, request for access_token but gives me Bad request response.


url = "https://www.reddit.com/api/v1/access_token"

payload={'grant_type': 'refresh_token',
'refresh_token': '-_DdTnxTXtIVyoZPT9JzhUNq3bGRjRg'}
files=[

]
headers = {
  'User-Agent': 'winserp',
  'Authorization': 'Basic *************************************************************************'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Response: {'message': 'Bad Request', 'error': 400}

Zain Nagi
  • 11
  • 1
  • perhaps you need to set the content-type and accept header to application/json in the header? as you are sending and receiving json data? – Tore Nestenius Dec 07 '21 at 14:21
  • still same error @ToreNestenius i made content-type and accept to application/json in headers but still same error of Bad Request – Zain Nagi Dec 07 '21 at 15:49
  • @ToreNestenius initially i made a request to same url with different payload ```payload={'grant_type': 'client_credentials', 'duration': 'permanent'}``` and getting access_token and refresh_token and then by using this refresh_token, i'm getting access_token with the above mentioned code but Bad Request error – Zain Nagi Dec 07 '21 at 15:53
  • Using client_credentials and refresh tokens does not make that much sense, see https://stackoverflow.com/questions/43340580/oauth-client-credential-flow-refresh-tokens – Tore Nestenius Dec 07 '21 at 16:17

0 Answers0