Extract your Strava data and display it anywhere!
I have been wanting to extract my Strava data and make a small dashboard for a long time. Finally I got around to doing it. I have been tinkering for some time, but I never bothered to understand the auth cycle fully, so I never got off the ground. Today I had an extra hour or two, so I finally got around to doing the data extract.
First you have to set up an application in your Strava account, see https://www.strava.com/settings/api. That I did years ago, it turns out.
Then you need to authorize. In order to do this, you have to define a callback url. That's where I have been banging my head against the wall, because I'm not making "an app", I just need access to the API. Hence, I have no page that can accept the callback. But it turns out you don't need to catch the callback. After granting the permissions in your browser, you can just let the callback to localhost fail. The refresh_token
you need to get access to the API, is displayed in plain text in the callback url, so it's very easy to extract. I figured that out by reading this post: https://medium.com/@sunny_codes/strava-api-request-all-activities-data-node-js-811c2e7b0261
Then it was just a matter of extracting the data from the api, which is explained properly in the official docs here: https://developers.strava.com/docs/reference/#api-Activities-getLoggedInAthleteActivities
I have a decent amount of activities, nothing new really happens with the old ones, so I decided to store all the activities in a sqlite database and only fetch the newest 100 activities each time I call the API, and then overwriting those in the database. That speeds up the process quite a lot.
I will use this in CI in order to make some stats for my website. A first pass at some analytics is here.
I gathered all the functions in a small click CLI, available in the gist below.