Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stravalib Authorization Error #111

Open
habi opened this issue Jun 7, 2023 · 3 comments
Open

stravalib Authorization Error #111

habi opened this issue Jun 7, 2023 · 3 comments

Comments

@habi
Copy link

habi commented Jun 7, 2023

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
Copy link
Author

habi commented Jun 7, 2023

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

@FABallemand
Copy link

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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants