Getting through authentication using the "stravalib" for Python 3.4 (Windows 7)

1,684 views
Skip to first unread message

Jerry Tyrrell

unread,
Dec 24, 2014, 10:57:52 AM12/24/14
to strav...@googlegroups.com
Using python 3.4 -- I'm just trying to get through the authentication stage. Haven't used python before, I'm learning a little because the stats program I use can't get through the authentication.

What even does this line mean? (the one in yella) I get that we're trying to extract the code, but what does the comment refer to and what is 'code' supposed to be replaced with? This is from: https://github.com/hozn/stravalib/blob/master/README.md

from stravalib.client import Client

client = Client()
authorize_url = client.authorization_url(client_id=1234, redirect_uri='http://localhost:8282/authorized')
# Have the user click the authorization URL, a 'code' param will be added to the redirect_uri
# .....

# Extract the code from your webapp response
code = request.get('code') # or whatever your framework does
access_token = client.exchange_code_for_token(client_id=1234, client_secret='asdf1234', code=code)

# Now store that access token somewhere (a database?)
client.access_token = access_token
athlete = client.get_athlete()
print("For {id}, I now have an access token {token}".format(id=athlete.id, token=access_token))



Thanks all!

Dan Jay

unread,
Dec 24, 2014, 1:07:39 PM12/24/14
to strav...@googlegroups.com
That line is just getting the code from the query string after the user has authorised the application.

Have a look at the Strava API Documentation, it explains it pretty well: http://strava.github.io/api/v3/oauth/

Hans Lellelid

unread,
Dec 31, 2014, 1:05:39 PM12/31/14
to strav...@googlegroups.com
Sorry, I just saw this.  I wrote stravalib, so I can help, though it sounds like Dan answered this for you already.

I should make the comment a little more specific.  Basically, the "code" parameter is something that Strava will append to the redirect URL as a query string parameter.  This means you need to be running a webserver / web application. In my example, I am assuming that you are running a python web framework and you would use whatever mechanism that framework exposes to get the value for the "code" query parameter.  Once you have the code, you perform that next step to exchange it for the more-permanent authorization token.  Once you have the token, you can just keep that (e.g. in a database) and use it for all future requests [for that athlete].

Hope that helps!

Hans

Eric Otofuji

unread,
Aug 2, 2016, 7:41:50 PM8/2/16
to Strava API
Hi, Hans!

I am having trouble going through authentication. I am new to this and I don't really understand how it works. May you help me indicating something I should try in order to get started with stravalib authentication? I would like to learn this! Thanks!
Reply all
Reply to author
Forward
0 new messages