0

I'm trying to use the reddit API to pull text data for a project, but I can't get the OAuth access token. Instead of responding with the access token, the response just says bad request.

Here's my code:

data={'grant_type':'authorization_code','code':'authcode which I got from the get request before','redirect_uri':'https://www.google.com/'}
r=requests.post('https://www.reddit.com/api/v1/access_token',data=data,auth=('client ID','client Secret'),headers={'User-Agent':'Rishi'})
print(r.text)

this what I'm getting

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

Triple checked the personal use script and secret, and so I'm struggling to think of what's wrong. Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • What headers has your response (add `print(r.headers)` to check that)? – Daweo Aug 20 '23 at 11:31
  • 400 is often used as a catchall response that just means "you did something wrong". Often there's no way to tell exactly what the problem is. – John Gordon Aug 20 '23 at 20:39
  • APIs often expect to receive their data input via json. Do you know if the reddit API expects json? Your code does not send json. – John Gordon Aug 20 '23 at 20:40
  • Looking at the [documentation](https://www.reddit.com/dev/api/), I don't see any url that matches `/api/v1/access_token`. Where did you get that url? – John Gordon Aug 20 '23 at 20:42

0 Answers0