How To Download Fitbit Data Using Google Spreadsheets: An Update

Editors Note: We’ve updated this post to reflect Google’s move to a new version of their spreadsheet application. The newest version no longer support the Script Gallery mentioned here. We have included a link in the instruction steps below that allows you to use the old version of Google Spreadsheets. We’ll keep an eye out and update this post again if the old version is taken down. We’ve also included a new set of instructions if you’d like to use the new Google Spreadsheets. This involves slight editing to a simple script (updated 09/22/14).

We’ve updated the script to reflect Fitbit’s move to only accept HTTPS requests to access their API. Make sure to update your own scripts if you’ve modified the one linked below in Step 4 (updated 10/15/14).

If you’re like me, then you’re always looking for new ways to learn about yourself through the data you collect. As a long time Fitbit user I’m always drawn back to my data in order to understand my own physical activity patterns. Last year we showed you how to access your Fitbit data in a Google spreadsheet. This was by far the easiest method for people who want to use the Fitbit API, but don’t have the programming skills to write their own code. As luck would have it one of our very own QS Meetup Organizers, Mark Leavitt from QS Portland, decided to make some modifications to that script to make it even easier to get your data. In this video below I walk you through the steps necessary to setup your very own Fitbit data Google spreadsheet.

Step-by-step instructions after the jump.

Set up your Google spreadsheet and script

Create a new google spreadsheet. Important: You must use the old version of Google Sheets. You can access that here - g.co/oldsheets (If you want to use the new version of Google Spreadsheets skip to Step 2.)

Fill in your application information. You can call it whatever you want.

Make sure to click “Browser” for the Application Type and “Read Only” for the Default Access type fields.

Read the terms of service and if you agree check the box and click “Register”

Copy the API keys

Copy the Consumer Key.

Copy the Consumer Secret.

You can save these to a text file, but they are also available anytime you return to dev.fitbit.com by clicking on the “Manage my Apps” tab.

Authorize the Fitbit Download Script

Go back to your Google spreadsheet.

Go to Tools->Script editor

If you have chosen to run the new version of Google Spreadsheets you must download this script, copy it’s contents, and paste into the script editor window. Make sure to delete all text in the editor before pasting. You can then follow along with the instructions below.

Select “setup” in the Run drop down menu. This will open a dialog box in your spreadsheet.

In your spreadsheet past the Consumer Key and Consumer Secret that you copied from your application on dev.fitbit.com.

Enter the day to start retrieving data. If you know when you purchased your Fitbit I would suggest using that date.

Select the data you want to save to your spreadsheet. By default all available Fitbit data is selected.

Click “save setup”

Go back to your script editor window

Select “authorize” in the Run drop down menu. This will open a dialog box in your spreadsheet. Click yes.

A new browser window will open and ask you to authorize the application to look at your Fitbit data. Click allow to authorize the spreadsheet script.

Download your Fitbit Data

Go back to your script editor window

Select “sync” in the Run drop down menu. This will download your Fitbit data to the spreadsheet.

Set up an automatic trigger to automatically update your spreadsheet with new data on a specific schedule.

Go to Tools->Script Editor

Go to the “Resources” menu and select “current project’s triggers”

Add a new trigger that runs “sync” that is ‘time driven’ and choose an interval for the spreadsheet to update. I currently have mine set to “daily” updating between “midnight to 1am” but feel free to choose something different.

Click save.

Now that you’ve set it all up your Fitbit data will automatically be downloaded to that spreadsheet. As you may know, there are a wide variety of charts and Google Gadgets that you can use to visualize that data.

If you’re using this method to look at your Fitbit data we want to know! Use the comments below to tell us what you’re learning from your Fitbit data and what types of visualizations or analysis you find most useful.

In 2. when you register your website url, note that Fitbit’s verification algorithm requires “http://” in front of your domain (duh‽)
1n 4. you’ll find the date field at the bottom of the script in yyyy-mm-dd format
In 5. “Sync” not “syn”

Dear Ernesto,
The google sheet works absolutely fine.
I am a doctor and use the fitbit flex on different patiënts (elderly).
I can change the name of the user on the website. How can I get the name in the spreadsheet? Do you know the name of the variable? It is not ‘name’ or ‘username’.
Thanks for this piece of work.

That’s great, thanks! Do you know about any option to get a data by hours (or even minutes if possible)? It would be great to look at the activity patterns in a finer resolution (that is hourly rather then daily, for example).

Other than using Fitabase, does someone know of a method to download intraday (by minute) data to Google Docs? I have access to the intraday data. Can someone advise how to modify this script to allow for data by minute?

I am a professional commodity trader that loves to use fitbit export data in conjunction with excel to devise a plethora of charts/analysis, many of which are taken from traditional technical analysis. Examples include weight charts with 7 day moving average and Bollinger bands, which represent + and – 2 standard deviations from the mean and describe my expected range of weight values. Other examples include the use conditional if/then statements to analyze and compare metrics on days that I work out, drink alcohol, meditate, etc, with “regular” days. The list goes on and on and I’ve actually recently started a personal blog to cover this exact topic: http://sciencetrainer.blogspot.com/
I haven’t updated it in a while, but keep an eye out, I will be going into detail on these and other related topics in the days and weeks ahead.

I do all my food entry in MyFitnessPal (PC and android app) – which IMHO is a much better way than using Fitbit’s limited calorie/food management section.

Is it possible to have this Google Spreadsheet also grab the diet/meal values from Fitbit?
I know that the data is there, as when I did exported my Fitbit data (7 day trial only – from the webpage), it downloaded all the MyFitnessPal data that it had synced over the previous months.

Any ideas how would I go about adding these fields into the Google Spreadsheet?

This is really useful, I finally could lay hand on what’s rightfully mine.
One thing, though. It would be really great, and much more interesting, if we could download all of our intraday data. The data exists, one can view it on Fitbit’s site, but there’s yet no way to download it, not even through the premium service!

Hi NIcolas – Our experience is that it is sometimes possible to get permission directly from Fitbit to look at this data, and I know Fitbit is cooperating with public health and academic researchers to study intraday data with permission from users, but you’re right, as of now there is no standard way for regular users to get it. I hope and expect that this will change!

I had a thought for a workaround to get intra-day data, and would love some feedback.
The hack assumes
a)your device is set to sync regularly (via smartphone background sync or the like), and
b) the fitbit download script “sync” was set on an hourly trigger

What I haven’t looked into is whether there is a way in google spreadsheets to add a “timestamp” column to record the time of each sync, and then run a simple subtraction formula in an additional column to get your hourly data?

I also don’t know how often the fitbit one will “background” sync with one’s smartphone, if that option is checked…

On the FitBit website, change the country for the food database in your settings, to US for Imperial measures. UK is metric, aside from weight, which is in decimal Stones. Any other country and it’s all metric.

Today I can download two days of data. It seems that the earliest data I can download data is the day I registered the script app. Anyone else experiencing that? It doesn’t matter what date I set the start date to in the script setup.

Thanks. This is great. Anyone else having an issue where the dates are off? It seems like all the dates are one greater than they should be except for the last row which is correct. This shows as the last 2 rows having the same date.

The Step 4 actions can be performed without going to the script editor. They can be accomplished from the Fitbit menu on the spreadsheet itself.

It is actually confusing to go to the script editor because when you click Run->setup in the script editor the dialog you want to interact with pops up in the spreadsheet. In a tabbed browser that dialog is no apparent because you’re looking at the script editor tab.

I suggest rewriting Step 4 to do both the setup and authorize actions from the Fitbit menu without ever going to the script editor.

This is great! I’m hoping to get some good information out of this data. However, when my spreadsheet syncs to my account, the dates and data seem to be out of sync slightly. For instance, today’s data is downloaded twice – once for my steps and calories burned, and then another set of separate data (i.e., an entirely different row) for my calories in, BMI, and weight. any thoughts why this is happening? I was hoping to find that this has happened to someone else as well.

Would it be possible to add Fitbit’s “Total Time Asleep” data to this script?
If you sleep in multiple sessions or nap, the minutesAsleep data will be inaccurate because it captures only one session from the day.

This is awesome. I have an extensive set of spreadsheets I’ve been manually curating to help me keep off 186 lbs. (weighted moving average of pounds, tracking body composition, estimating TDEE based on what the scale does, etc.)

Now I’ll only have to track my food in LoseIt as usual, and if I get one of those wi fi scales I won’t even have to log my weight by hand…

My problem is I can’t get the caloriesIn data, even I can see them on Fitbit dashboard.
Does it depend from the origin of the data, Myfitnesspal?

Is it possible to specify in which Sheet to sync? -if I let the script sync by trigger, it appends data in front of the first sheet, already filled by Withings and IFTTT… I have to run sync manually when in another sheet. Thank you

Thank you for the brilliant script! It’s very easy and straightforward to set up and run.

However, I do have the same issue as Jonathan Hyland above, the dates seem to be off a day, apart from the caloriesIn which seem to be OK (the calories are syncing from MyFitnessPal, so it could be they are correct because they sync a day later, haven’t looked into it in more detail)

I’m glad to hear so many people are having success with the script, and want more functionality than the original script provided. I will revisit the Fitbit API and see if some of these requests (such as downloading BP and other logged parameters) can be satisfied.

I only have steps data in my own records, so I’ll need a few beta testers who have BP, weight, and other logged parameters, and who are willing to share credentials with me so I can test on their data. Anyone interested?

I use the script to download my data daily, while I do not use the BP feature there are a few things that I use that are not downloaded. They are Floors Climbed; Time to Bed (AM PM format); Time in Bed (HH:MM format). I am willing to help test.

If you are interested in being a beta tester, please connect up with me via email so we can keep your credentials off the web. just remove the ?’s from this and you have my email address: m?ark@mark?leavitt.?com

Rod: That’s an interesting idea! I believe something like that could be done. See this video on using twilio with Google apps script to send SMS and voice. How many think this would be a killer feature? Maybe we can get some programming help from others.

“Now that you’ve set it all up your Fitbit data will automatically be downloaded to that spreadsheet. As you may know, there are a wide variety of charts and Google Gadgets that you can use to visualize that data. For instance, here’s my Fitbit data from 1/1/13 to 2/18/13:”

As in: what this spreadsheet pulls is great, but it’s only what the device tracks automagically, right? Where’s my food intake/composition information? Does Fitbit keep that for themselves or is it also API accessible?

Gadgets, by the way, is no more , but I see it’s just a matter of creating my own graphs so … no biggee.

What I’d love to see is the de-conglomeration of the food data. Caloric intake is not so special and is actually represented well enough in your work (did I say thanks enough? ). But, for example, I’ve noticed as I’ve been using my Flex for the last few weeks that my protein intake is relatively low compared to what I always believed it to be, and calories don’t really give that information up unless FitBit’s data repository is splitting the information behind foods we log into permanent (held by them … yikes … insurance companies getting access … ) data categories that can be pulled. Given the speed with which the dashboard does the calculations I believe that must be so, but … I’m going a lot of wondering.

I didn’t realize all of this was so easily accessible, and I presume it’s the same API that FitBit is pulling from (OK, I HOPE this is right) to sell their $50/annum reporting service.

I have a question. How would I go if I only want the steps taken. I need the break down of steps like they display on the dashboard by 5 minutes increments. For example “105 steps taken from 10:00 to 10:05. As right now Im doing manually and is a very tedious job.

Inge, I have seen this problem occur. Please try clearing the browser cache, closing the browser, and retry the authorize command. If that doesn’t work, see if there is a popup blocker operating for the browser, and if so, disable it temporarily. Good luck!
Mark

Inge, if you would like we could use Google hangout or Skype to screen share, and try to troubleshoot. The script editor has some basic debugging/logging tools that we can run while attempting to authorize. It might help me figure out what’s not working. What time zone are you in?
Mark

I am not sure how to manage a screen share. Stupid, I know
I do have another question. What do you fill in on the the fitbit dev authorization screen? You say to call the app whatever you like . but should it not be the same name as the google spreadsheet ? What do you fill in on the other fields: application website, organization, call back URL. And how should the google spreadsheet be authorized, just me ?

Thanks for this excellent script!
It works great with day-to-day data, however I would like to visualize minute-to-minute resolution. I have a fitbit partner account. Would it be possible to extract minute-to-minute data by using your script? If not, do you have any suggestion how to do it in the fastest way? .. I am actually a researcher, currently in a rush to process some data so I am trying to avoid reading fitbit documentations and writing scripts from the scratch

Thank you in advance!

Best,
Alex

Inge > the same problem occurred to me. I resolved it by changing the settings in “Manage my apps” from “desktop” to “browser”. (it’s actually well explained above but I put it on “desktop” by mistake so this resulted in endless “running”.

did you find a way to do what you were asking in your post? Although I think you will only be able to get down to a 5-min resolution and not minute-to-minute resolution… I’ve seen this raised a couple of times but couldn’t find a satisfactory answer.

I’d be very interested if someone found a way to update the script to get data down to a greater resolution than on a daily basis.

Solved the problem. I did it all again and suddenly realized that the second “authorize” is not in the Fitbit pull down menu but on the script editor menu. Very stupid of me.
It is all working fine now.

Many thanks for posting this- very elegant and excellent instructions.

One quick follow up- I successfully generated the sheet and pulled some data, but am having the same problem as ‘John’ on March 7, where I’m only getting one day returned. Any ideas what I might be doing wrong as I should have a couple of month’s worth of data available.

Hi – I have a flex and a one under different email accounts. My flex is linked to gmail, the one is linked to a different account. Is there any way to authorize the one and have both datasets download to my google spreadsheet? It looks like I have to set up another gmail account to access the non-gmail tracker….

Love the script. Although I have weight data showing for the last couple of weeks, the BMI and fat data suddenly stopped. Fitbit website and mobile app show the weight data, BMI, and fat data, but the Google spreadsheet cells for the past 2 weeks are just blank. Any ideas?

In the past couple of days, something strange has happened to the Activity Score readings: now that column is reading “-1″. I noticed this in Beeminder, where the entries for 28 and 29 September show “-1″. In the Googledocs spreadsheet I created using these instructions, the entire column has “updated” to “-1″. What’s the recommended solution here? I’m guessing that Fitbit has changed some detail of its API (the other columns seem fine) and that has effected the data coming into both my Beeminder graph and the spreadsheet. So will copying the API keys and setting things up anew help? Or is there a better solution?

Thanks very much for developing and sharing this. I have the same question several others asked.

“Anyone else having an issue where the dates are off? It seems like all the dates are one greater than they should be except for the last row which is correct. This shows as the last 2 rows having the same date.”

This is line 145:
var o = Utilities.jsonParse(result.getContentText());

It is not clear to me what the problem is with getContentText, anyone know? Seems like it ran for a couple of days and then the last two days started shooting this error. I’ve just started looking into it, but hoped someone else might have solved it already. Thanks.

I am also having problems with the “Authorize” step. I have correctly entered all information in the “Setup” phase, but the “Authorize” script fails to run. Has something changed with Fitbit policy or with the Fitbit API? Any help would be great!

I was very excited to find this and hoped to learn a little about programming along the way. However, after following the instructions a few times, I am still getting rows of dates, but no values for steps. Calories are recorded (at a default rate, I assume) as are 1440 sedentary minutes (24 hours per day). I am also unable to see today’s steps in the fitbit iphone app, which makes me thing that the problem lies with my device.

If there’s a “for dummies” text, please point me in that direction, though I suspect this activity is not for dummies.

I am also interested in importing body measurements like waist, bicep etc. I tried the same as subaron did to add body body/bicep body/log/bicep etc to loggables. I get error downloading …error 400 I think. What am I missing?

Ok, I found the problem with importing body measurement data. The api will not except a date range with the /body/ resource. When only the start date is submitted in the GET the 400 error goes away. Furthermore, the /body/ resource has a bunch of data fields within it that must be parsed out and dealt with(titles created, data filled) one date at a time. This indicates to me that all the data should probably be handled differently, and some way of selecting each measurement in the setup function would be nice.

I was able to print one value to a test spreadsheet by editing as follows.(don’t do this to your live spreadsheet lol)

Ok, impatient as I am, I went ahead and wrote code for importing body measurements.
Caveat: my code is long winded and far from eloquent. Clumsy at best.
But it works, I’ll clean it up tonight and then I’m happy to share it.
The same methods I used can be used to pull any data down from fitbit, but further looped parsing will need to be added to accommodate food logs and activity logs.
Currently my code must run on the same synced sheet as the rest of it. So you may want to make a copy before testing.

Bisono, yes you can. But it would be easiest IMO to do this with multiple spreadsheets and 1 script/user per spreadsheet. Set these scripts to time trigger, and write a script to import the spreadsheets’ data into one sheet.

It could be done in one sheet with one script with some pretty major changes as it would require multiple authorizations, multiple oauth tokens etc. Also username would have to be logged into the sheet, it is not currently.

And of course you are trying to display 3 dimensions of data in 2 dimensions, so layout should be a concern. How many users are you talking about?

For some users, Im able to retrieve the steps, but others not, because authorization. Do you know if those users by changing their privacy setting, I then will be available to retrieve that info? Thanks for your answer.

I THINK so, haven’t tested it. You would need their encoded user id I think.
This is the last letters and numbers after the last / of public URL, can be found on users profile page. you would then enter that info in place of the dash (-) in the fetch, and not use the oAuth token. Again, I have not tried this but I believe its possible if they have this data set to “Anyone” in their privacy settings. If it works it wouldn’t be too much trouble to do this in one script.(for someone good at writing scripts, but I’m happy to help.)

To whomever is interested,
I now have functions written into this script for body measurements, heart rate, and blood pressure. I am still cleaning it up a bit, but I am happy to make it available to anyone that wants it. Its still a bit clunky, and there may be date related errors that I haven’t found yet. I am new to JSON, FitBit, and Google Docs, lol.
Once its tested a bit, I am happy to help modify this for everyone’s needs.

Jim, that would be amazing if you could! I have created an email ryan_quantified@hotmail.com. Your work on figuring this out is very much appreciated. I tried but my coding knowledge is very limited. Thank you again in advance!
Ryan.

Thank you for this fantastically informative tool! I have encountered an error when at the authorize step. A box appears “App Script Error Attempting Authorization” with an “ok” tab. Can anyone please help?

has anyone figured a way to rig a silent alarm to remind you to get up and move if you have been sedentary too long? I’m thinking you could create an active pct base don the sum of the active minutes / minutes sedentary and set an alarm if it fell below a target threshold.

This is a feature I’ve recently added to TRAQS (http://traqs.me). Silent alarms are created based on inactivity, and thresholds are defined based on daily/weekly goals. The plan is to include this in the next beta round in a few weeks If you’re interested feel free to signup for the beta and we’ll get you on the list to try it out as soon as it’s ready.

Joe, that would be one way to do it. However, you will be getting lots of alarms after you first get up. The target percentage would change throughout the day. I would go about it as follows: set to sync every 30 min. compare steps with steps 30 minutes ago, if difference < 50 set alarm for now() plus 5 minutes. put all this in an 'if 6am < now() < midnight {}' so you don't get alarms all night, then json.stringify the alarm time and post to fitbit.

I have a physical exam tomorrow and I just discovered this script. I’m trying to modify to retrieve blood pressure, also, but I can’t figure out the parameters. Could you send me the data, also or post your code?

In my case, it refuses to authorise the device. It either gives me an “authorization error”, or gets stuck at “running script”. i have tried getting and setting new keys, but nothing seems to make it work. Any ideas?

The spreadsheet isn´t working any longer since 1. April 2014 for me. I now geta daily error message “TypeError: Methode “getContentText” von undefined kann nicht aufgerufen werden. (Zeile 145, Datei “fitbitdownload”)” from Google Apps.
I remember I got a mail from fitbit that they would change something regarding their developer APIs a few weeks ago, so I suppose they changed the method how one can get his data, and the script is therefor not working any longer.
Please leave a comment if you are still able to collect your fitbit data with this script (or what I need to change to get it working again) – or add a comment on an alternative way to get to your data, if you know one.
Thanks & stay fit!

I tried accessing “the old version of Google Spreadsheets” etc per your 25 June comment, but nothing about FitBit appears in any menu that I see, and there’s no obvious place to paste my Client Key and Client Secret.

Programming a spreadsheet is unfamiliar to me, so I’d second DG12′s suggestion for an update to the directions at the start of this article if you get the time.

I had success getting the script working in the ‘new’ Google Sheets by opening up the script editor, creating a new spreadsheet script, copying and pasting the code, and running the steps as described above.

I’ve just done one sync, so no long term testing, but hopefully it continues to work.

Hi guys – switched to the updated script + new google spreadsheet but I get errors when it tries to run overnight along the lines of ‘please select an actice sheet first (line 125, file code). When I manually run the sync from the spreadsheet, I get an error message “Error downloading activities/log/activityCalories” after which the sync continues if I close he error message.

I get the following error: Please select an active sheet first. (line 114, file “Code”) when I try to run the script from a time trigger. The script works run manually. Any help is greatly appreciated.

Putting getSheetByName as it’s own line cleared up the setFrozenRows error, and then I found that without specifying both the ID and the sheet name, everything worked fine manually, but failed on the timed trigger. This method has it all working for me now.

Hi
Just getting started with the API and I was getting the same error. As of Nov 3, connections to api.fitbit.com are restricted to HTTPS. Just search through the script and change http to https and ‘you off to the races’.

I’m getting an API depreciated error saying to calls may be removed in the future

ScriptProperties API is deprecated.Collapse
File: Fitbit_Data.gs Line: 181
The API has been marked as deprecated which means that the feature should be avoided and may be removed in the future. Consider using an alternative solution.
Method Utilities.jsonParse is deprecated.Collapse
File: Fitbit_Data.gs Line: 43
The method has been marked as deprecated which means that the feature should be avoided and may be removed in the future. Consider using an alternative solution.

I can’t get my “authorize” function to work. It keeps telling me “Authorization is required to perform that action.” I believe it’s supposed to open a dialog box and then a webpage that allows you to ‘authorise’ access to your fitbit account, but mine doesn’t do anything at all, just comes back with that error message. Any ideas?

I’ve received the same error today and no matter what I try, I can’t fix it. I was able to find a solution in ‘Library’ on July 7th but it’s back to the same error from them and it’s unrepairable. Please help! I’m NOT a techie at all. Just a dedicated Fitbit user who relies on the daily downloaded Google spreadsheet to keep me focused.

Are you going to be updating this information since Google is using a new OAuth script. I know absolutely nothing about this kind of scripting but want to update my Google doc spreadsheet to keep up with my Fitbit data.

I tried to follow the Video but with the new googledoc form, I only find under “Add on” one result if I look for “fitbit”.
This result, however, is not “FitBit download” but “FitBit Activity Importer” and it only imports a few data and only from the last 30 days.
Moreover I dont Need an application Login for that.

Can you tell me how I can get all the Information you get in the Video?

Does anyone know how to pull macros data (carbs, protein, fat) using this script? I’ve tried adding several types of calls but nothing is working. I don’t know how to format the request to get that information, or is it even more involved?

Partners

Sponsors

Friends of QS

We recently started a program to invite QS Toolmakers to contribute directly to funding our events. We call this program Friends of QS. If you would like to participate we invite you email us to learn more.