Last active
March 28, 2023 07:36
-
-
Save mrpbennett/b52b16ddf44c61508c37ae868a4830fd to your computer and use it in GitHub Desktop.
Get auth token for Strava - python
This file contains hidden or 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
def get_strava_token() -> str: | |
""" generates Strava Auth token and returns it """ | |
auth_url = "https://www.strava.com/oauth/token" | |
payload = { | |
"client_id": "xxxx", | |
"client_secret": "xxxx", | |
"refresh_token": "xxxx", | |
"grant_type": "refresh_token", | |
"f": "json", | |
} | |
print("Requesting Token...\n") | |
res = requests.post(auth_url, data=payload, verify=False) | |
return res.json()["access_token"] | |
# --------------- | |
strava_endpoint = "https://www.strava.com/api/v3/xxxx" | |
headers = {"Authorization": f"Bearer {get_strava_token()}"} | |
param = {"per_page": 200, "page": 1} | |
strava_data = requests.get(strava_endpoint, headers=headers, params=param).json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment