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!
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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?
Best AnswerI 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?
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Yes, I will report that bug to engineering. Thank you!
Best Answer