10-13-2023 05:39 - edited 10-13-2023 06:09
10-13-2023 05:39 - edited 10-13-2023 06:09
I am using the intraday api after having received the relevant authorisation.
However, when I make api calls to fitbit, some users (it doesn't seem to happen to everyone) receive them status code 401.
To give you a bit more context, I am using the api calls from a mobile app made in flutter and the fitbitter package, which does not handle intraday calls but I have adapted it, everything seems to work in the test environment, only some users have this problem and I can't understand why.
There is the url i m calling:
'https://api.fitbit.com/1/user/${fitbitCredentials.userID}/activities/${resourceToString[resource]}/date/$startDateStr/$endDateStr/1min/time/$startTimeStr/$endTimeStr.json'
For example my complete url is:
'https://api.fitbit.com/1/user/AAAAA/activities/steps/date/yyyy-mm-dd/yyyy-mm-dd/1min/time/15:45/23:59.json'
The two dates are same day for intraday api constraints
Answered! Go to the Best Answer.
10-18-2023 05:15
10-18-2023 05:15
Yes, I have already received authorisation.
I have discovered that there is a problem with the flutter library for the fitbit I am using in that it does not regenerate the tokens correctly, so for the first 8 hours it works, then failing to regenerate the token it makes calls with an expired token, the 401 is definitely due to this.
Thank you very much for your support.
10-13-2023 12:23
10-13-2023 12:23
I think you might get a 401 if the user hasn't provided permission for your app to access the data you're requesting.
Some intraday data need Fitbit approval (see here).
10-15-2023 08:15
10-15-2023 08:15
Thank you for your reply.
I have actually already done this step with my app and received permission to use this type of api. is there perhaps an extra step to take when I call api to have my app recognised as authorised for intraday?
10-15-2023 11:57
10-15-2023 11:57
The only reason I can think of for intermittent 401s would be for users who haven't authorised your app's use of the specific data you're trying to access.
10-16-2023 09:52
10-16-2023 09:52
I will try to investigate this, I too cannot honestly explain it, I will ask to my users. Thank you for your reply.
10-16-2023 12:22
10-16-2023 12:22
Hi @Kirus
At 401 can be caused by several things. See https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/error-messages/#401-unauthorize.... The most common issues are
The access tokens have a lifespan of 8 hours. Once they expire, you need to use the refresh token to obtain a new access token/refresh token pair. Along with verifying the user consented to activity, have you verified if the access token is still active?
Gordon
10-17-2023 02:21
10-17-2023 02:21
Before each api call the library automatically checks if the token has expired and if so it is regenerated. Surely this is not the third case, I am investigating with my users to see if they have given authorisation. The alternative is that the library does not regenerate the token correctly, I will check this too.
Thank you very much for your help.
10-17-2023 11:27
10-17-2023 11:27
Just to confirm the 3rd scenario is not an issue, have you applied for intraday access and gotten approval?
10-18-2023 05:15
10-18-2023 05:15
Yes, I have already received authorisation.
I have discovered that there is a problem with the flutter library for the fitbit I am using in that it does not regenerate the tokens correctly, so for the first 8 hours it works, then failing to regenerate the token it makes calls with an expired token, the 401 is definitely due to this.
Thank you very much for your support.