05-12-2021 17:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-12-2021 17:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I added the app to my Dev screen, and used the Python file from the repo. I have two LEDs in my program. a "Connected" green LED and an "Auth error" red LED. But every time I launch the app, it's saying 0 steps, 0 calories, etc, the green LED stays off, and the red LED turns on every time I launch the program. What should I do to successfully auth the program?
05-13-2021 09:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-13-2021 09:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It's not exactly clear to me what you are doing. I have a few questions for you.
- Does this application run on the Fitbit smart watch (Verse, Ionic, Sense) or this is a mobile application?
- Are you using the Web APIs to retrieve a user's activity data?
- Has a user authorized your application to share their Fitbit data?
- Which API(s) are you executing to get the Fitbit data? Are you getting an error message in your code?
Thanks!
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

05-13-2021 10:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2021 10:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
IT is a Windows app. I am using python-fitbit to collect the data. I authorized myself. Without the try/except I got HTTPUnauthorized.

05-13-2021 11:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-13-2021 11:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Would you please post the endpoint that you're executing which receives the HTTP Unauthorized error? Also, include the headers and their values EXCEPT for the access token.
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

05-13-2021 11:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2021 11:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
authd_client = fitbit.Fitbit('23B52F', 'c16643cd3596c02103a2d82f47fb91be',
access_token='https://api.fitbit.com/oauth2/token', refresh_token='<refresh_token>')

05-13-2021 12:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-13-2021 12:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Are you trying to exchange the authorization code for the access token and refresh token, or are you trying to refresh an expired access token?
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

05-13-2021 12:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2021 12:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm trying to get a token for the first time.

05-13-2021 12:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-13-2021 12:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you. I'm going to provide you with the API syntax, but you'll need to translate that into your python code. The syntax is
POST https://api.fitbit.com/oauth2/token
Authorization: Basic <basic token>
Content-Type: application/x-www-form-urlencoded
client_id=<client_id>&grant_type=authorization_code&redirect_uri=<callback URL value>&code=<authorization code>
The authorization code can be found appended to the redirect_URL after the user consents.
I don't think the code you provided is providing the correct information. If you want to test the authorization process with your own client settings, we provide the OAuth 2.0 Tutorial to help with that. See https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/debugging-tools/#oauth-2-0-tuto....
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

05-13-2021 15:29 - edited 05-13-2021 16:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2021 15:29 - edited 05-13-2021 16:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Gordon-C I got an OSError when trying to open the activity log.
act_list=open('https://api.fitbit.com/1/user/-/activities/date/2021-05-13.json', 'r')
OSError: [Errno 22] Invalid argument: 'https://api.fitbit.com/1/user/-/activities/date/2021-05-13.json'

05-13-2021 16:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-13-2021 16:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Sounds like you got past the authorization error. Great news! This new error is not coming from the Web APIs. Researching the error online, it seems the error related to your python code syntax. We do not support the developer communities open source projects. So, maybe one of the community developers can assist with this error.
If you want to test the endpoints outside of python, I can suggest a few free tools you can use to make certain the data is available.
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

05-13-2021 16:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-13-2021 16:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Gordon-C When clicking it it says
{"errors":[{"errorType":"system","fieldName":"n/a","message":"Authorization Error: Invalid authorization token type"}],"success":false}

05-13-2021 18:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-13-2021 18:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It seems to me that you're trying to open a file. Instead, you need to do internet request-response stuff.
Gondwana Software

05-14-2021 04:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-14-2021 04:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Urlrequest.urlopen returns 401 error. @Gondwana.

05-18-2021 10:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



05-18-2021 10:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
When you receive the 401 Unauthorized error, would you PM the follow items
- your client ID
- the endpoint that your executing when the error occurs
- all of the headers and their values for the above endpoint.
Thanks!
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

