How to Download Minute-by-Minute Fitbit Data

NOTE: The methods detailed in this post no longer work. The post is kept here for archival purposes, but unfortunately you will not be able to access your Fitbit data by following the steps.

IntradayDataChart

Earlier this week we posted an update to our How To instructions for downloading your Fitbit data to Google Spreadsheets. This has been one of our most popular posts over the past few years. One of the most common requests we’ve received is to publish a guide to help people download and store their minute-by-minute level step and activity data. Today we’re happy to finally get that up.

The ability to access and download the minute-by-minute level (what Fitbit calls “intraday”) data requires one more step than what we’ve covered previously for downloading your daily aggregate data. Access to the intraday data is restricted to individuals and developers with access to the “Partner API.” In order to use the Partner API you must email the API team at Fitbit to request access and let them know what you intend to do with that data. Please note that they appear to encourage and welcome these type of requests. From their developer documentation:

Fitbit is very supportive of non-profit research and personal projects. Commercial applications require additional review and are subject to additional requirements. To request access, email api at fitbit.com.

In the video and instructions below I’ll walk you through setting up and using the Intraday Script to access and download your minute-by-minute Fitbit Data.

  1. Set up your FitBit Developer account and register an app.
    • Go to dev.fitbit.com and sign in using your FitBit credentials.
    • Click on the “Register an App” at the top right corner of the page.
    • 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.”
  2. Request Access to the Partner API
    • Email the API team at Fitbit
    • They should email you back within a day or two with  response
  3. Copy the API keys for the app you registered in Step 1
    • Go to dev.fitbit.com and sign in using your FitBit credentials.
    • Click on “Manage My Apps” at the top right corner of the page
    • Click on the app you created in Step 1
    • 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.
  4. Set up your Google spreadsheet and script
    • Open your Google Drive
    • Create a new google spreadsheet.
    • Go to Tools->Script editor
    • 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 “renderConfigurationDialog” in the Run drop down menu. Click run (the right facing triangle).
    • Authorize the script to interact with your spreadsheet.
    • Navigate to the spreadsheet. You will see an open a dialog box in your spreadsheet.
    • In that dialog paste the Consumer Key and Consumer Secret that you copied from your application on dev.fitbit.com. Click “Save”
    • Navigate back to the scrip editor window.
    • Select “authorize” in the Run drop down menu. Click run (the right facing triangle).
    • 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.
  5. Download your Fitbit Data
    • Go back to your script editor window.
    • Edit the DateBegin and DateEnd variables with the date period you’d like to download. Remember, this script will only allow 3 to 4 days to be downloaded at a time. 
    • Select “refreshTimeSeries” in the Run drop down menu. Click run (the right facing triangle).
    • Your data should be populating the spreadsheet!

If you’re a developer or have scripting skills we welcome your help improving this intraday data script. Feel free to check out the repo on Github!

This entry was posted in Lab Notes, Personal Projects and tagged , , , , , , , . Bookmark the permalink.

42 Responses to How to Download Minute-by-Minute Fitbit Data

  1. ted w says:

    Great info – thanks – unfortunately at last step get error:
    “TypeError: Cannot read property “dataset” from undefined. (line 131, file “Code”)”

    Suggestions?

  2. PC says:

    Yep – same error here for me too.

    Any ideas, anyone?

  3. Ernesto Ramirez says:

    Hmm…I’m having trouble recreating the error, but looking into it.

  4. ey says:

    Thanks for this. Once I heard back from FitBit, I had no problem running the script.
    I have a question and a request: Will the latest data write over what is already in the spreadsheet or do I have to start a new worksheet or file?
    Could I check if it is possible to modify the code to let it download the current day’s data and set a trigger to do so daily?

  5. Peter Robinson says:

    I would like to give this a try but the registration page requires a website for the app and also an organisation name and web site. What do you do as a private individual using a spreadsheet with no interest in creating web sites just to get through the registration?

    • Peter Robinson says:

      ok, replying to my own question, just put anything at all in there, it doesn’t matter. I did, however, create a google page where I will publish my analytics until I get something permanent done and used the url of that page.

  6. Dan Allen says:

    I also ran into the same error message. I made the request to fitbit, got the reply asking for my consumer key, and got this back: Fitbit- Customer Support Case #: 2220735.

    Is this normal?

    Thanks,
    Dan

  7. Taren says:

    This is fantastic. Great work on this.

    I’m wondering if there is a way to pull the heart rate data (from Chrage HR/Surge) as well? It’s not listed in the Get-Time-Series API, does that mean it’s unavailable?

  8. Lea says:

    I would really like to download as much minute-to-minute sleep data as possible. Does anyone know how to modify the script to accomplish this?

  9. NikFromNYC says:

    Ditto: TypeError: Cannot read property “dataset” from undefined.

    I had to discover the newly created Fitbit menu within the spreadsheet to try to grab data easily.

    Also, I only asked for two days data but it seems rather odd to offer only this: “Remember, this script will only allow 3 to 4 days to be downloaded at a time.”

    Huh?! That makes this whole exercise useless to me. I need a month at a time.

  10. Patrick says:

    hello , first of all thank you for posting this , it’s been really helpful to my research.
    however when I modified your code to get minute by minute sleep data I also get this message :
    “TypeError: Cannot read property “dataset” from undefined. (line 131, file “Code”)” , my key has been authorized ( can get intraday step data without any problem)

  11. Csaba says:

    Hi Ernesto,

    I amanged to setup the excel file however when I try to authorize the app, I am asked to login to the Fitbit site where after authorizing the app, the page displays a PIN and the script wil continue to run without me being prompted for any action.

    If I try to download the data, the cells are not populated.

    Can you please help me out?

    Thanks,

    Csaba

  12. psysorens says:

    Can anyone make a suggestion about how I should ask the Fitbit API staff for my minute by minute data? I sent them an email, but did not even get a response… I do have some experience working with data from triaxial accelerometers and would like to make more use of Fitbits in my research (kids like them a LOT better than acticals, actigraph, etc…), but as-is, my analyses are really constrained by the data that I can currently get from the devices. Any suggestions would be greatly appreciated!

  13. NotConvinced says:

    Yes, back in October FitBit decided to delete everything you care about from the Export data API.
    (Get-Body-Measurements) See https://wiki.fitbit.com/display/API/Fitbit+API

    October 2014 Deprecations
    The following API endpoints are deprecated and will be removed at a future date:
    API-Get-Heart-Rate (will be replaced with heart rate time series endpoints)
    API-Log-Heart-Rate
    API-Delete-Heart-Rate-Log
    API-Get-Blood-Pressure
    API-Log-Blood-Pressure
    API-Delete-Blood-Pressure-Log
    API-Get-Glucose
    API-Log-Glucose
    API-Get-Body-Measurements
    API-Log-Body-Measurements

    All measurements except fat and weight will be removed from:
    API-Get-Body-Measurements
    API-Log-Body-Measurements

    Because they haven’t replaced these with something new already, it can be assumed that it is part of the business model to deprive us of OUR DATA and to drive yearly subscriptions up. Meanwhile our data is now crowd/cloud data that is being used by Johns Hopkins & other major research facilities, which I approve of, but to withhold it from me the purcha$er & end uSer, just pi$$es me off!

  14. NewAPI says:

    Fitbit just updated their API to include intraday for the following:

    activities/calories
    activities/distance
    activities/elevation
    activities/floors
    activities/heart
    activities/steps

  15. Jonathan says:

    I follow all steps but when i go to authorise in the script error all i get is message saying “Authorization is required to perform that action” in red. No pop up window appears so i cant move ahead with the download data or refresh time series functions. so frustrating!!! Please help

    • tes says:

      I’ve have been getting the same error for the past couple days and haven’t found a solution yet.

      It seems to be happening at this line of code:
      var result = UrlFetchApp.fetch(“https://api.fitbit.com/1/user/-/profile.json”, options);

      Also I’ve read some warnings about the oAuthConfig library being sunset-ed, so that could be part of the issue too (https://developers.google.com/apps-script/migration/oauth-config). I haven’t been successful in altering the code to use an Oauth2 library yet so I don’t know for sure.

      If anyone finds a resolution please share :)

    • csaba says:

      check whether your app is web based.

    • tes says:

      Hey Jonathan,
      I was able to get past the auth issue by running the authorize function in debug mode (little bug button).

      Now I’m fighting the “TypeError: Cannot read property “dataset” from undefined.” bug lol

  16. skala says:

    Out of curiosity, is this currently working for others?

    After running “authorize”, I’m getting the following error and the spreadsheet only creates column names for Date and steps.
    “TypeError: Cannot read property “dataset” from undefined”

    If I change line 132 to:
    var row = o[intradays[activity]];

    then my spreadsheet populates only column names for “Date steps calories floors elevation”. Nothing else is populated in the spreadsheet.

    Any ideas would be greatly appreciated.

  17. April Aralar says:

    Has anyone else gotten the error while clicking authorize in the run drop down menu immediately after entering in the consumer key and secret of “Script is using OAuthConfig which has been shut down. Learn more at http://goo.gl/IwCSaV (line 277, file “”)” from the script editor?

    I’m kinda stuck here, and I followed the URL and found no helpful information to solve this problem. Can anyone advise?

    • April Aralar says:

      Although I am following the Google step by step process of migrating to the new OAuth1 system, I am still having trouble understanding what needs to be updated in the code. If anyone has an updated script that will run with the new system, that would be greatly appreciated. Thanks!

    • City17 says:

      I’m having the same problem. Found a solution by any chance?

  18. Gina says:

    I am getting the same error as April at the same place–section #4, “Select “authorize” in the Run drop down menu. Click run (the right facing triangle).

    • Gina says:

      Found a script that will download the Intraday data for steps using OAuth 2.

      https://github.com/simonbromberg/googlefitbit

      Posted a followup to the dev about heart rate data on this FitBit Dev thread.

      https://community.fitbit.com/t5/Web-API/Google-apps-script-for-minute-by-minute-data-stopped-working/td-p/754197

      • Matt H says:

        user named Gthm solved the problem over at FitBit community forums
        https://community.fitbit.com/t5/Web-API/Google-apps-script-for-minute-by-minute-data-stopped-working/m-p/890582#M2685

        Here’s what Gthm posted:
        It turns out that this was an invalid scope/permissions error. Some of the changes I made for the script to be working

        1) When requisting Oauth2 the default permission scope does not include heart rate. It pretty much includes everything but heart rate and calories. So for better measure I explicitly granted scope.

        In function getFitbitService() { // updated the below line
        .setScope(‘activity heartrate location nutrition profile settings sleep social weight’)

        2) Update the activities and intradays variables accordingly

        var activities = ["activities/heart"];
        var intradays = ["activities-heart-intraday"];

        3) Request the proper URL for heart rate. The API docs are not clear enought, especially near the URL templates. I got the last template of the API docs working for heart rate.

        It was easier for me to hardcode the URL so I just replaced the featch call with this

        var result = UrlFetchApp.fetch(“https://api.fitbit.com/1/user/-/activities/heart/date/2015-07-07/1d/1sec/time/00:00/23:59.json”, options);

        Once you get this request to work, you can generalize and construct the above request dynamically based on user inputs.

  19. Barry says:

    If any of the readers here are having a problem getting this to work, or just want to “try out” a similar working solution, I am providing this facility for members who use my Squash Leagues website. You can try it out for yourself here – Download your Fitbit Data

  20. Ben says:

    I’m having trouble with the script. It says, “Script is using OAuthConfig which has been shut down. Learn more at http://goo.gl/IwCSaV (line 278, file “Code”).” Any ideas on how to get this to run?

  21. Izzy says:

    I’m having a problem after I clicked play button (after chose renderFitbitConfigurationDialog), the red exclamation mark appears in the light-bulb and showed many lines of error

    UiApp API is deprecated.Expand
    File: Code Line: 230
    FlowPanel API is deprecated.Expand
    File: Code Line: 270
    Grid API is deprecated.Expand
    File: Code Line: 259
    Button API is deprecated.Expand
    File: Code Line: 274
    Label API is deprecated.Expand
    File: Code Line: 239
    ServerHandler API is deprecated.Expand
    File: Code Line: 267
    UiInstance API is deprecated.Expand
    File: Code Line: 230
    TextBox API is deprecated.Expand
    File: Code Line: 244

    Well, when I click Expand, it shows the same messages of error which is “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.”

    Please help!

  22. Agnes says:

    I have been using the Fitbit Blaze and find it intolerable that access to my own data is either restricted, requires a yearly fee, or needs special programming. The Basis Peak I had been using allowed free and easy access to data (heart rate, perspiration, skin temp, calories, and steps) in CVS format from their app in minute intervals for at least 2 years at a time. Their sleep algorithm also appears to be superior. Alas, they have recalled all watches and will stop access in Dec 2016.

    Although the Fitbit has some good features, restricted data access is a killer for me (I’m sure most users are not interested in becoming programmers or spending time trying to get scripts to work). I will be returning the Fitbit Blaze and hope Basis or some other company replicates Basis’ generosity in allowing easy access to all of an individual’s own data.

Leave a Reply to Matt H Cancel reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.