Getting your Fitbit Data

2018-Jan-25, Thursday 01:25 pm
I do not know why I was put off getting my Fitbit data through the official channels for so long. Something about OAuth2.0 seemed intimidating. But it's really not. It's just filling out a web form. This is a really good walk through of the process.

Just fill in all the fields here they insist you do, making sure to select 'Personal', and for my purposes at least, 'Read-Only'. Once created you'll see it listed on your apps page. If you follow the link from there to the OAuth 2.0 tutorial page it populates all the fields. You click on the link they tell you to, copy the long parameter list from the url, throw it into the Parse Response section, and it will create the Request for you. You can then use it through the browser with Hurl It, copy the curl command into a terminal, or start building HTTP Requests in the language of your choice. To get different data you just change the API Endpoint URL. (If you selected 'Personal' you'll have access to all the Intraday records as well.)

That really is it. Now you can start writing programs to pull down all your data and save to file. (Requests are limited to 150 an hour.) And then the real super fun bit of visualising all that data, at all those different granularities begins.



One day graph of fitbit data; sleep and heartrate
Photo by [personal profile] chebe

This weekend involved getting to see Placebo in concert, so not much else happened. But that's the great thing about software, you can be productive without getting out of bed.

I recently attended a Quantified Self meetup on sleep, that gave me the kick up the arse I've been needing. (Which was only compounded when I heard about Pebble closing, and that Fitbit would take over their servers, and staff.) One of the presenters talked about how he got his Fitbit data and how he analysed it. (If you're interested, slides are here, and blog post here.) He switched to using the official APIs when they became available, but I went with his original approach, a python program to log in and get your intraday data points instead of the aggregated stuff you get on the dashboard.

I haven't been the most steady wearable user, but there were a few months when I wore it reliably. Simply because I was sleeping terribly and wanted to understand just how badly. Although I never got around to actually analaysing the data, until now. (That's one thing about all these QS talks, typically everyone showing their data is the picture of good health. I'm more interested in seeing what it looks like when it goes wrong.)

I used the website dashboard to find the months that actually contained data. Then I exported csv files, month-by-month, using the official export option. This is the aggregated information, but it will be nice to see if it correlates with the intraday info.

Then armed with dates that contain valid data, I put them into the python program, and grabbed all my data. In short, download and extract the source code. In the same folder as setup.py create your own python file, where you will create your own client. (This information is apparently in the example files, but I poked around before I noticed that.) To create your own client you just pass in your email address and password;
client = fitbit.Client.login(email="bob@example.com", password="password")
You grab the specific info you're interested in;
client.intraday_sleep(date)
And then dump it to screen/file/whatever you want. Although it's a good idea to format it a little.

Sleep data is recorded as one value per minute.

# The different values for sleep are:
# 0: no sleep data
# 1: asleep
# 2: awake
# 3: very awake

# data will be a similar list of tuples, but spaced one minute apart
# [
# (datetime.datetime(2010, 2, 20, 23, 59), 2),
# (datetime.datetime(2010, 2, 21, 0, 0), 1),
# (datetime.datetime(2010, 2, 21, 0, 1), 1),
# ....
# (datetime.datetime(2010, 2, 21, 8, 34), 1),
# ]


And then, we are left with the task of analysing the data. Which is a much bigger one.

Profile

chebe: (Default)
chebe

Syndicate

RSS Atom

July 2025

M T W T F S S
 1 23456
78 910111213
14151617181920
21222324252627
28293031   

Expand Cut Tags

No cut tags

Style Credit