Last active
September 10, 2022 13:06
-
-
Save odunola499/1e39cd630592814d180cdcd46ade5777 to your computer and use it in GitHub Desktop.
further
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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