Skip to content

Instantly share code, notes, and snippets.

@mrpbennett
Last active March 28, 2023 07:36
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 mrpbennett/b52b16ddf44c61508c37ae868a4830fd to your computer and use it in GitHub Desktop.
Save mrpbennett/b52b16ddf44c61508c37ae868a4830fd to your computer and use it in GitHub Desktop.
Get auth token for Strava - python
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