5

I've been using the Fitbit Python package to analyse my data. When I look at my exercise data it seems to work really well:

fitbit_stats = authd_client._COLLECTION_RESOURCE('activities', date='2015-09-16')

However, when I try to get my heart rate data, it runs, but doesn't return anything except 0s:

fitbit_stats = authd_client._COLLECTION_RESOURCE('heart', date='2015-09-16')
print fitbit_stats

{'heart': [], 'average': [{'tracker': 'Resting Heart Rate', 'heartRate': 0}, {'tracker': 'Normal Heart Rate', 'heartRate': 0}, {'tracker': 'Exertive Heart Rate', 'heartRate': 0}]}

Does anyone know why I'm not returning any data here?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Jack Simpson
  • 1,681
  • 3
  • 30
  • 54
  • 1
    FWIW, I suspect it's a bug. I registered on dev.fitbit.com, cloned the latest python-fitbit repo, gathered my OAuth2 credentials, created a fitbit.Fitbit instance with oauth2=True, and could gather everything I tested except heart rate. I didn't dig further, but was able to get the data using the API tester here: https://www.connect2.me/fitbit/fitbit-heart – radicalbiscuit Sep 17 '15 at 08:14

1 Answers1

5

The following will work but I'm not sure this is what you are looking for

fitbit_stats = authd_client._COLLECTION_RESOURCE('activities/heart', date='2016-08-11')
print fitbit_stats

I'm guessing you want the intraday date (like me)

According to https://dev.fitbit.com/docs/heart-rate/#get-heart-rate-intraday-time-series

Access to the Intraday Time Series for personal use (accessing your own data) is available through the "Personal" App Type.

Access to the Intraday Time Series for all other uses is currently granted on a case-by-case basis. ...

I've added a custom function to the fitbit api package:

def get_heartrate_intraday(self, date="today", end_date="1d", detail_level="1sec", user_id=None):
    uri = "{0}/{1}/user/-/activities/heart/date/{date}/{end_date}/{detail_level}.json"

    date = self._get_date_string(date)
    end_date = self._get_date_string(end_date)

    url = uri.format(
        *self._get_common_args(user_id=user_id),
        date=date,
        end_date=end_date,
        detail_level=detail_level
    )
    return self.make_request(url)

The data this will return looks like:

'activities-heart-intraday': {
    'dataset': [
        {'time': '00:00:00', 'value': 66},
        {'time': '00:00:10', 'value': 67},
        {'time': '00:00:25', 'value': 67},
        {'time': '00:00:40', 'value': 67},

        {'time': '23:57:40', 'value': 84},
        {'time': '23:58:40', 'value': 85},
        {'time': '23:58:50', 'value': 80}
    ],
    'datasetInterval': 1,
    'datasetType': 'second'
}
PvdL
  • 1,578
  • 1
  • 20
  • 33