06-12-2024 05:43 - edited 06-12-2024 05:47
06-12-2024 05:43 - edited 06-12-2024 05:47
I've recently started looking into the FitBit API because I wanted to play around with my charge 6. following the python implementation suggested on the developers portal and other websites always bring me to the following issue:
KeyError: 'activities-heart-intraday'
sample code running with python 3.10
import gather_keys_oauth2 as Oauth2
import fitbit
import pandas as pd
import datetime
CLIENT_ID='xxx'
CLIENT_SECRET='xxx'
server = Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET)
server.browser_authorize()
ACCESS_TOKEN = str(server.fitbit.client.session.token['access_token'])
REFRESH_TOKEN = str(server.fitbit.client.session.token['refresh_token'])
server = Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET)
server.browser_authorize()
ACCESS_TOKEN = str(server.fitbit.client.session.token['access_token'])
REFRESH_TOKEN = str(server.fitbit.client.session.token['refresh_token'])
auth2_client = fitbit.Fitbit(CLIENT_ID,CLIENT_SECRET,oauth2=True,access_token=ACCESS_TOKEN,refresh_token=REFRESH_TOKEN)
yesterday = str((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y%m%d"))
fit_statsHR = auth2_client.intraday_time_series('activities/heart', base_date=yesterday, detail_level='1sec')
time_list = []
val_list = []
for i in fit_statsHR['activities-heart-intraday']['dataset']:
val_list.append(i['value'])
time_list.append(i['time'])
heartdf = pd.DataFrame({'Heart Rate':val_list,'Time':time_list})
YES: my app is set on 'personal'
YES: I authorized the data usage
YES: I tried to remake the app from scratch.
Any further suggestion?
Thanks a lot!
09-09-2024 12:58
09-09-2024 12:58
Hi @S4m
I saw your posted your question in the wrong forum and I moved it to the correct one. Are you still getting this error messge?
01-22-2025 13:18
01-22-2025 13:18
I seem to have the same issue, I wrote my app from scratch, the app is set to Personal, yet I don't get activities-heart-intraday from something like https://api.fitbit.com/1/user/-/activities/heart/date/<date>/1d/1s.json which I should according to the documentation.
I played around with the OAuth way of authorizing, but to no ends. Any other suggestions?
01-22-2025 13:34
01-22-2025 13:34
Hi @MarcusMT
You have a typo in your endpoint. The detail level for HR in seconds is "1sec", not "1s". Please try changing your endpoint syntax and let me know if that doesn't work.
01-23-2025 00:16
01-23-2025 00:16
That was it, doh, now it works.
This would be a good candidate to not respond with a 200 OK
01-23-2025 08:16
01-23-2025 08:16
Yes, I will report that bug to engineering. Thank you!