Search code examples
pythonapiauthenticationimgur

Python authorize imgur OAuth2.0 authentication to fetch subreddit gallery


So I'm trying to access the imgur API for the list of images in a certain reddit subgallery. This is what I've tried so far:

>>> header = {'client_id': 'thisismyclientid', 'response_type': 'pin'}
>>> r = requests.get('https://api.imgur.com/oauth2/authorize', headers=header, verify=False)
>>> r.text
u'{"data":{"error":"client_id and response_type are required","request":"\\/oauth2\\/authorize","parameters":"","method":"GET"},"success":false,"status":400}'

Not entirely sure what I'm doing wrong, is this not the correct way to pass my client_id and response type?


Solution

  • Quick look at the documentation reveals:

    https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE
    

    Those are get parameters, not headers. So you have to pass the dictionary as params instead of headers.