The Hub is now in read-only mode as we make improvements to the Hub experience. More information is available here.
01-23-2024 10:38 AM
Wondering if someone could help - I'm trying to obtain totals for an athlete. I have managed to get all activities, but would also like totals.
This is the following code I am using:
stats_url = f"https://www.strava.com/api/v3/athletes/{client_id}/stats?" \
f"access_token={access_token}"
statsresponse = requests.get(stats_url)
stats = statsresponse.json()
print('Stats API:', stats_url)
ride_total_year_calculated = round(stats['ytd_ride_totals']['distance']/1000,1 )
When copy and pasting the URL I get the following response:
{"message":"Forbidden","errors":[]}
I'm obviously doing something really stupid here, but can't see it right now!
For further info, the following works:
activities_url = f"https://www.strava.com/api/v3/athlete/activities?" \
f"access_token={access_token}"
print('RESTful API:', activities_url)
response = requests.get(activities_url, params=params)
print(len(response.json()))
for i in range(0,len(response.json())):
activity = response.json()[i]
print('Disance:', activity['distance'], 'm')
print('Date:', activity['start_date'])
print('type:', activity['type'])
Solved! Go to Solution.
01-23-2024 02:29 PM - edited 01-23-2024 02:37 PM
stats_url = f"https://www.strava.com/api/v3/athletes/{client_id}/stats?" \ f"access_token={access_token}"
Did you mean to insert client_id there? That should be athlete_id
See: https://developers.strava.com/docs/reference/#api-Athletes-getStats
GET | /athletes/{id}/stats |
id required Long, in path | The identifier of the athlete. Must match the authenticated athlete. |
01-23-2024 06:02 PM
That's a good point - however that is set to my athlete ID. The URL looks like this (with x's as actual athlete id):
01-23-2024 02:29 PM - edited 01-23-2024 02:37 PM
stats_url = f"https://www.strava.com/api/v3/athletes/{client_id}/stats?" \ f"access_token={access_token}"
Did you mean to insert client_id there? That should be athlete_id
See: https://developers.strava.com/docs/reference/#api-Athletes-getStats
GET | /athletes/{id}/stats |
id required Long, in path | The identifier of the athlete. Must match the authenticated athlete. |
01-23-2024 06:37 PM
You’re absolutely right, thank you so much
Welcome to the Community - here is your guide to help you get started!