Last active
August 29, 2015 14:10
-
-
Save alanhamlett/cfadfbe2ee45011f8de9 to your computer and use it in GitHub Desktop.
OAuth example
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
#!/usr/bin/env python | |
import base64 | |
import requests | |
ACCESS_TOKEN = "XXX" | |
APP_SECRET = "XXX" | |
# get some JSON, authenticating with url args | |
r = requests.get('https://wakatime.com/api/v1/users/current/stats/complete', params={'access_token': ACCESS_TOKEN}) | |
print(r.json()) | |
# it also accepts access_token as just token | |
r = requests.get('https://wakatime.com/api/v1/users/current/stats/complete', params={'token': ACCESS_TOKEN}) | |
print(r.json()) | |
# get some JSON, authenticating using Basic Auth (Authorization header) | |
headers = { | |
'Authorization': 'Basic {key}'.format(key=base64.b64encode(ACCESS_TOKEN + ':' + APP_SECRET)), | |
} | |
r = requests.get('https://wakatime.com/api/v1/users/current/stats/complete', headers=headers) | |
print(r.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment