Skip to content

Instantly share code, notes, and snippets.

@odunola499
Last active September 10, 2022 13:06
Show Gist options
  • Save odunola499/1e39cd630592814d180cdcd46ade5777 to your computer and use it in GitHub Desktop.
Save odunola499/1e39cd630592814d180cdcd46ade5777 to your computer and use it in GitHub Desktop.
further
#with our secret key and client id we create our basic requests authentication
auth = requests.auth.HTTPBasicAuth(client_id, secret_key)
data = {
'grant_type':'password', #mode of authentication
'username' : username,
'password' : password
} #dictionary with our username, password and type of authentication
headers = {
'User-Agent' : 'your app name'
}
#using the request post method send our credentials and retrive a temporary access token
res = requests.post('https://www.reddit.com/api/v1/access_token', auth = auth, data = data, headers = headers)
token = res.json()['access_token'] #retrieving our access token from the res response json
#now we can add our access_token to the headers dictionary. the headers dictionary would be what we use to get the actual data we need
headers['Authorization'] = f'bearer {token}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment