Skip to content

Instantly share code, notes, and snippets.

@alanhamlett
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhamlett/cfadfbe2ee45011f8de9 to your computer and use it in GitHub Desktop.
Save alanhamlett/cfadfbe2ee45011f8de9 to your computer and use it in GitHub Desktop.
OAuth example
#!/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