from stravalib.client import Client
from httplib2 import Http
client = Client()
client_id, client_secret = open('client.secret').read().strip().split(',')
# Have the user click the authorization URL, a 'code' param will be added to the redirect_uri
# .....
# Extract the code from your webapp response
code = request.get('code') # what do I do here?!
access_token = client.exchange_code_for_token(client_id=client_id, client_secret=client_secret, code=code)
# Now store that access token somewhere (a database?)
client.access_token = access_token
athlete = client.get_athlete()
print(
f"For {athlete.id}, I now have an access token {access_token
}")