fitbitScraper Examples

Cory Nissen

5/5/2016

Installation

Install fitbitScraper as you would a normal library. It exists on CRAN, so a simple install.packages("fitbitScraper") should work.

A development version exists on Github, and can be installed via devtools. devtools::install_github("corynissen/fitbitScraper")

Usage

I’ve stored my password in an environment variable called “FBPW”. I’ll use this to login to fitbit and generate a cookie that will be used for the subsequent requests. You can type it directly in the password field, but it is generally a best practice to use an environment variable instead. Fitbit allows login via Google and Facebook. This library only works with an email / password based login.

You can get a daily summary of your data also. Here, I download data for the number of flights of stairs I climbed for the last two months. Then, compute the average number of flights of stairs by day, and graph it. Not surprisingly, I climb more stairs on the weekends when I’m home than I do at work during the week. Note that it is possible to get this data using get_intraday_data() for each day, but this is much more efficient using just one call to the fibit API for the entire date range instead of one API call per day.

Another thing to look at, especially if you have the Aria scale, is your weight. You can record your weight manually in the fitbit app, which is how I do it, or the Aria scale will sync it automatically. Any how, let’s graph my steps vs. weight for a time period and see if there seems to be a correlation. Data is returned for use in a graph on the fitbit page, so if you include a date range larger than two weeks or so, it returns data for a subset of the days in your range. Fitbit seems to play pretty loose with the start and end dates too. I want data from 2015-01-01 to 2015-05-01, so I’ll break that into several requests to fitbit.

That last example illustrates one of the limitations of retrieving the data the way this library does. Instead of using the “official” fitbit API, this library uses the API intended for their website developer to use to build the visualizations on the web dashboard. So, there’s no public documentation. This results in situations like the last one where the weight data returned by that API call is intended to be used in a chart, so they don’t need more than 20 points, so that’s all that is returned, no matter how large the date range supplied is. Keep this in mind when you request data and use caution that you are being returned data for the same dates that you requested it for.