strava-api-experiment
strava-api-experiment copied to clipboard
Strava API Experiment
This project is my personal experiment with Strava's API. As an almost daily user of Strava recording private/commute rides as well as the occasional long weekend workout ride, I have some ideas for working with my own personal data as well as public community data, but I am not ready to package this tool for public consumption yet (e.g. as a published lib or web app).
This is an "afternoon project" for the time being, so I don't guarantee or claim any foresight or quality. Use or borrow this code at your own risk!
Support this project on Gittip
Ideas
- analyze the breakdown between public vs. private activities
- analyze workout vs. commute bike rides
Note: there's a site called VeloViewer which already does a bunch of fancy analytics and visualizations with your Strava data, so you might want to check that out. However, it's not open source (as far as I can tell).
What's inside so far
- a simple OAuth client to get a write-permission
access_token
(for developer use) - some starter utilities to analyze my personal ride data
3rd Party Dependencies
- hozn's stravalib
- Python libs listed in requirements.txt
Exploring the API for your own data
- create a new Python virtualenv (highly recommended)
-
git clone [email protected]:anthonywu/strava-api-experiment.git
-
cd strava-api-experiment
- with the project virtualenv activated:
pip install -r requirements.txt
-
Register your app with Strava, then get the
client_id
andclient_secret
parameters from https://www.strava.com/settings/api -
cd src
, examine the source of./strava_local_client.py
or run./strava_local_client.py -h
- this is a script that interacts with Strava's OAuth endpoints to give you a write-access token - Run the local OAuth client:
./strava_local_client.py get_write_token <client_id> <client_secret>
. The client will provide an url (or on OS X, launch your default browser to that url) which directs you to a strava.com page that lets you authorize write-access to your account. After you authorize the usage, the OAuth callback returns to thelocalhost
-hosted client app with acode
that the client then exchanges for anaccess_token
. Your browser should display theaccess_token
as the response. You can now use this write-permissionaccess_token
to view and modify your own user data. - Getting on the Python command line to play with the API:
STRAVA_API_TOKEN=<access_token> konch
e.g.
$ strava-api-experiment/src $ STRAVA_API_TOKEN=<...> konch
utils: <module 'utils' from 'strava-api-experiment/src/utils.pyc'>
client: <utils.MyStravaClient object at 0x10edc9050>
In [1]: client.get_athlete_clubs()
Out[1]:
[<Club id=11111 name=u'BAF' resource_state=2>,
<Club id=22222 name=u'LS' resource_state=2>]
See stravalib documentation on how to use the client
object.
Enjoy!