Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get OAuth access/refresh tokens with Python?

My program opens a page using the request urls in which the user logs into. They then authorize us to use their data, and then are redirected to the callback uri (the localhost) + a code. I am able to parse this code at the end of the callback out, but I am not sure how to use it or what to do with it to get the access/refresh tokens. Any help greatly appreciated. 

Best Answer
0 Votes
1 REPLY 1

Hi @RajPatel57.  I would recommend checking out the OAuth 2.0 Tutorial page to walk through the OAuth flow.  This is the URL: https://dev.fitbit.com/apps/oauthinteractivetutorial.   However, you can also access it from our application's settings page in the dev.fitbit.com management portal, and we will fill in all of the values for you.

 

OAuth 2.0 Tutorial - Access Point.png

 

After you get the code for the callback URL, you'll trade the code for the access token and refresh token.  Here's an example from our documentation.

 

POST https://api.fitbit.com/oauth2/token
Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded

client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Ffitbit_auth&code=1234567890
Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer