flopp / GpxTrackPoster

Create a visually appealing poster from your GPX tracks
MIT License
411 stars 50 forks source link

stravalib Authorization Error #111

Open habi opened 1 year ago

habi commented 1 year ago

I've updated the stock strava.json with my info from https://www.strava.com/settings/api, akin to

{
    "client_id": "12345",
    "client_secret": "somerandomcharacters",
    "refresh_token": "morerandomcharacters",
}

Then I run create_poster --from-strava strava.json --year 2023, but the process fails with an error in stravalib. The error is stravalib.exc.AccessUnauthorized: Unauthorized: Authorization Error: [{'resource': 'AccessToken', 'field': 'activity:read_permission', 'code': 'missing'}].

On the Strava API page I also see an 'Access Token' for my account, do I have to enter that somewhere, too?

habi commented 1 year ago

I have an export file from Strava, too, but https://github.com/flopp/StravaExportToGPX fails to convert those into GPXs...

FABallemand commented 7 months ago

I had the same issue. Here is how I modified track_loader.py in order to get everything to work:

client = Client()
#### line 137
scope = ['read', 'profile:read_all', 'activity:read']
url = client.authorization_url(client_id=strava_data["client_id"], redirect_uri='http://127.0.0.1:5000/authorization', scope=scope)
print("Open the following URL, give authorisation and wait to be redirected")
print(url)
print("Copy/paste the value of code from the url of the page you were redirected to...")
code = str(input())
client = Client()
token_response = client.exchange_code_for_token(client_id=strava_data["client_id"],
                                                client_secret=strava_data["client_secret"],
                                                code=code)
ACCESS_TOKEN = token_response['access_token']
REFRESH_TOKEN = token_response['refresh_token']  # You'll need this in 6 hours
# REFRESH
# token_response = client.refresh_access_token(client_id=MY_STRAVA_CLIENT_ID,
#                                              client_secret=MY_STRAVA_CLIENT_SECRET,
#                                              refresh_token=REFRESH_TOKEN)
# ACCESS_TOKEN = token_response['access_token']
# REFRESH_TOKEN = token_response['refresh_token']  # You'll need this in 6 hours
client = Client(access_token=ACCESS_TOKEN)
####
# response = client.refresh_access_token(**strava_data)
# client.access_token = response["access_token"]
filter_dict = {"before": datetime.datetime.utcnow()}
koronicsnorbert commented 7 months ago

I had the same issue. Here is how I modified track_loader.py in order to get everything to work:

client = Client()
#### line 137
scope = ['read', 'profile:read_all', 'activity:read']
url = client.authorization_url(client_id=strava_data["client_id"], redirect_uri='http://127.0.0.1:5000/authorization', scope=scope)
print("Open the following URL, give authorisation and wait to be redirected")
print(url)
print("Copy/paste the value of code from the url of the page you were redirected to...")
code = str(input())
client = Client()
token_response = client.exchange_code_for_token(client_id=strava_data["client_id"],
                                                client_secret=strava_data["client_secret"],
                                                code=code)
ACCESS_TOKEN = token_response['access_token']
REFRESH_TOKEN = token_response['refresh_token']  # You'll need this in 6 hours
# REFRESH
# token_response = client.refresh_access_token(client_id=MY_STRAVA_CLIENT_ID,
#                                              client_secret=MY_STRAVA_CLIENT_SECRET,
#                                              refresh_token=REFRESH_TOKEN)
# ACCESS_TOKEN = token_response['access_token']
# REFRESH_TOKEN = token_response['refresh_token']  # You'll need this in 6 hours
client = Client(access_token=ACCESS_TOKEN)
####
# response = client.refresh_access_token(**strava_data)
# client.access_token = response["access_token"]
filter_dict = {"before": datetime.datetime.utcnow()}

Work like a charm!