Fitbit Data Fun

The Fitbit website actually does a relatively good job of parsing and displaying this daily data for casual perusal and offers a value added "personal trainer" service to take your data and guide you toward health goals. There are some nice provided charts which show the minute-by-minute steps/intensity as well as plots of sleep and floors of stairs. The interface is relatively intuitive and allows modifying date ranges and sharing your aggregated data to your friends on the site. Unfortunately, if you're the type who would like to do a bit of your own work with your data you, like me, will soon encounter difficulties.

Fitbit offers a simple API service which registered developers can make use of to grab quite a bit of user information, but the best bits like intraday step and intensity data are restricted from everybody but the Fitbit partners. Fitbit partners you say, well I'll just register as one of those in that case! Wrong. It is not currently possible to register as a partner directly as that option is only available for large partner companies.

I found this somewhat unfortunate as I thought I was purchasing a well engineering piece of hardware to acquire data for me, not exclusively for partners of an Internet company. This seemed even more peculiar since the five-minute data is available in the graphs on the web interface. Fortunately this means that there must be some API call to refresh the graphs on the beautiful AJAX pages as we select among the different days.

Indeed, using the standard trick of using the chrome developer tools while engaging with the elements on the webpage we quickly notice there's one specific style of request made to request what looks like graph data. Mimicking the style of request it's actually possible to acquire this data directly in python provided we mimic the cookies (which is accomplished by using the cookie jar and urllib modules in python to actually login to the site).

To this end I compiled a very rudimentary script capable of fetching the intraday data that is now posted on github for anybody who also finds a need to play with their data.

To use it you would do something like the following (to get raw files not just data)

git clone https://github.com/smalley/FitbitIntraday.git

from datetime import datetime,timedelta
from FitbitIntraday import FitbitIntraday

fbi = FitbitIntraday()

fbi.login('example_fitbitemail@example.com','example_password')

start_day = datetime(2013,5,1)
end_day = start_day + timedelta(days=7)
folder_path = '/my/path/here'

fbi.fetch_range_to_folder('calories',folder_path,start_day,end_day)
fbi.fetch_range_to_folder('steps',folder_path,start_day,end_day)

Happy data hacking!

posted Sun 25 August 2013 by Sean Malley

Sean Malley is a software engineer working in California.

Find Me

Mastodon
Github
LinkedIn

© Sean Malley 2009-2024