updated pythonic adventures in fitbit land


After a long walk with the dog this morning i decided to enjoy the afternoon and start with python to get data from my fitbit.

The first step is to create an application on the https://dev.fitbit.com/ site, then i used gather_keys_oauth2.py then from https://github.com/orcasgit/python-fitbit to get the access and refresh tokens. There's plenty of information out there on how to do that part but i found the next step more complicated, all the python examples i found were above my ability some used Jupyter notebooks and some contradicted others so working my way through it slowly i codged together something which works but this is only the first step :)

import fitbit
from datetime import datetime, timedelta

# taken from the fitbit app creation site
CLIENT_KEY = 'spacemarine' # OAuth 2.0 Client ID
CLIENT_SECRET = 'eisenhorn' # Client Secret
# taken from the keys generated via gather_keys
USER_KEY = 'druss' # user_id
ACCESS_TOKEN = 'the' # access_token
REFRESH_TOKEN = 'legend' # refresh_token

# get a client
authd_client = fitbit.Fitbit(CLIENT_KEY, CLIENT_SECRET,
                             access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)

#Get sleep
fitbit_sleep = authd_client._COLLECTION_RESOURCE('sleep','2017-08-24')

print(fitbit_sleep)

So the above should get all the sleep data for the 24th August coincidentally my birthday :) running it gives output like;

{u'sleep': [{u'logId': 15590676884, u'dateOfSleep': u'2017-08-24', u'minutesToFallAsleep': 0, u'awakeningsCount': 9, u'minutesAwake': 11, u'timeInBed': 496, u'minutesAsleep': 481, u'awakeDuration': 5, u'efficiency': 98, u'isMainSleep': True, u

/img/fitbitoutput.png

python 

See also