Strava getting data from api

621 Views Asked by At

I was following tutorial https://towardsdatascience.com/using-the-strava-api-and-pandas-to-explore-your-activity-data-d94901d9bfde and this github https://github.com/franchyze923/Code_From_Tutorials/blob/master/Strava_Api/strava_api.py (proposed in tutorial). And cannot find solution to problem below, I found something about scope but do not know how to use it, thus I am here seeking help

{'message': 'Authorization Error',
 'errors': [{'resource': 'AccessToken',
   'field': 'activity:read_permission',
   'code': 'missing'}]}
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

auth_url = "https://www.strava.com/oauth/token"
activites_url = "https://www.strava.com/api/v3/athlete/activities"

payload = {
    'client_id': "XXXXXX",
    'client_secret': 'XXXXXX',
    'refresh_token': 'XXXXXXXXX',
    'grant_type': "refresh_token",
    'f': 'json'
}

print("Requesting Token...\n")
res = requests.post(auth_url, data=payload, verify=False)
access_token = res.json()['access_token']
print("Access Token = {}\n".format(access_token))

activities_url = f"https://www.strava.com/api/v3/athlete/activities?" \
          f"access_token={access_token}"
print('RESTful API:', activities_url)

# Get the response in json format
response = requests.get(activities_url)
activity = response.json()

I tried to change payload and find another solution but results were always as above. I receive my access token though

Access Token = 61766e12XXXX062XXX2a2eXXXXXXXXXX
1

There are 1 best solutions below

0
On

first of all, scope in strava api is something that represents what types of access are being granted to the app from a strava user account. it can be read user's public activity, read private activity, write etc.

in case of getting authenticated: strava uses oAuth2 and has a very detailed guideline to get started for the first time. You may check their official doc page: (https://developers.strava.com/docs/authentication/#oauthoverview).

the process is explained in very detailed and should be enough for your problem.