jat255 / strava-to-fittrackee

Connector to pull workouts from a Strava account and upload them to a FitTrackee instance
MIT License
11 stars 2 forks source link

Cannot setup tokens #4

Closed Mickey016 closed 1 year ago

Mickey016 commented 1 year ago

Hi,

I just discovered your script which look exactly what I was searching for a long time. Thanks for working on such a project !

Now, I'm trying to use it properly. I think I'm close to success but I obviously miss something when it comes to setting up tokens between Fittrackee and Strava.

My setup :

With that done, I'm able to launch the script s2f.py.

When I try to use the --setup-tokens parameter, the script provides me a link that let me access the expected Strava page. After validating it, I can copy the generated url and paste it back in the terminal. The script then crashes with the following logs : Capture d’écran 2023-02-28 à 21 19 48

I have tried the following changes with no luck so far:

At this point, I don't know if I'm encountering a bug (not sure) or if I'm making an obvious mistake (more likely). I apologize in advance for my far-from-perfect English, and I would be grateful if someone could help me.

jat255 commented 1 year ago

Hi @Mickey016, sorry for taking a while to get back to you on this. To be honest, I'm a bit stumped, as I didn't come across this sort of error in my development at all. I also just tested this on my own server again by re-downloading the code and running the setup-tokens flow in a new environment, and it completed fine for my Strava account (I realize "I can't reproduce it" is a less then satisfying response, but I am not sure how to debug if I cannot see the same issue as you)

I used the same application and redirect URL as you, and my URL to paste into the terminal looked like:

https://localhost/?state=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&scope=read,activity:read_all

Which looks the same as what you put in your screenshot (with different specific state and code values). In my case, the web flow completes successfully and the code moves onto authenticating to my FitTrackee instance.


At first I thought maybe the source of the problem was that your reverse proxy or specific FT server configuration was different than what I had when I developed it, but this error is actually occurring entirely with the Strava side of things (i.e. before your FitTrackee instance is involved at all), which means it doesn't have anything to do with any of the settings you put in your FitTrackee application registration (the localhost stuff). Perhaps try creating a new test Strava account just to test if your current account is somehow not working with the flow (although that seems unlikely...)

Presumably, the issue is related to those described here: https://github.com/requests/requests-oauthlib/issues/324 But without being able to debug your failing case in more detail, it'll be hard to figure out exactly what's going on.


With regards to:

  • tinkering with website and domains parameters

As far as I understand, these can generally be whatever you want, as they are not actually used by the code (they just determine where you get redirected after authenticating. Using a bogus URL there is why after you get redirected, the web browser shows an error, but the URL that you paste in is what gets parsed to extract the token information.

jat255 commented 1 year ago

Oh! Just as a test, I tried running through the token flow with incorrect values for STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET in the .env file. When I set an incorrect client id, going to the URL provided by the script gave me the following error (rather than displaying the Strava "Authorize" screen):

{
  "message": "Bad Request",
  "errors": [
    {
      "resource": "Application",
      "field": "client_id",
      "code": "invalid"
    }
  ]
}

However, if I use the correct STRAVA_CLIENT_ID, but an incorrect STRAVA_CLIENT_SECRET, I get shown the "Authorize" screen, and I get redirected to the localhost URL, but when I copy that URL into the terminal, I get your exact error:

oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

I wonder, could you double check that the value you have set for STRAVA_CLIENT_SECRET in the .env file matches the one shown here:

image

on the https://www.strava.com/settings/api page for your account?

It might be as simple as a misconfigured "password" setting, but with a totally unhelpful error message. I hope so, because otherwise I have no idea! :sweat_smile:

Mickey016 commented 1 year ago

Hi @jat255, don't bother for the delay, we all have more important things to do !

I have good news : everything seems to work fine now. I have strange news : it looks like it was not related to any of the things we looked at.

More details :

Anyway, now everything looks OK. My first sync is in progress, taking some tome because of the API rate limit.

Thank you for this app and your kind replies. This issue can be closed.

Keep up the good work 👍

jat255 commented 1 year ago

Awesome! I'm glad it ended up working for you. I guess I should have suggested the first rule of tech support (did you turn it off and on again? :wink: )

Based off the issue I linked to before, it sounds like that missing token error from oauthlib swallows whatever the actual error from the server is, so it's really hard to debug without attaching some sort of debugger. Anyway, glad you got it working, and I hope the script works out for you. I've been running it for about 5 months now and it just keeps chugging along in the background. I set mine up to have a cron job running python s2f.py --sync twice per hour, and after my runs/rides, I see them show up automatically in fittrackee, since I record using Strava or a GPS that automatically pushes to Strava.

Anyway, now everything looks OK. My first sync is in progress, taking some tome because of the API rate limit.

Yes, this is annoying. I don't think there's anyway to get around it without talking to Strava and becoming an "official" third-party integration, which I'm sure costs money... The sync tries to be smart about it and only fetch activities newer than what you have in FitTrackee, so even if you have to stop and restart it a few times, it should eventually work. Mine took two days I think when I first did it since I had about 200 activities. More prolific athletes will have to wait longer...