How To: Sync Fitbit Data to Google Spreadsheet

The following article is a step-by-step guide on how to sync Fitbit data into a Google spreadsheet. Update July 20, 2022 The original script for connecting a Fitbit account to...

The following article is a step-by-step guide on how to sync Fitbit data into a Google spreadsheet.

Update July 20, 2022

The original script for connecting a Fitbit account to a Google Sheets has some issues due to using outdated Google Script and soon-to-be deprecated Fitbit API. Thus, I want to bring your attention to the script by Josh Kybett, who has kindly edited it to get it working again. Considering he is also planning to maintain it, I wanted to share his work with you, so other people out there that come across my original article can benefit from it. You can download it at GitHub URL: https://github.com/JKybett/GoogleFitBit

That said, please use Josh's script instead of the one I posted below. It is as I mentioned actively maintained and also considered stable and not presently in need of changes/fixes:

- Modifications 2022 - Josh Kybett - [JKybett.uk](https://jkybett.uk/)

Replaced discontinued UiApp code to use HtmlService instead.

- Replace deprecated v1 FitBit API with current standard v2 FitBit API

- Now fetches data using daily summaries rather than per-item ranges to avoid hitting API limits when getting single-day data.

- Adapted to get data for more features of FitBit.

- Friendlier setup UI.

UPDATE AUG 2020:

I've changed the code on this page as it no longer worked.  The new working version of this script is now posted on the following page: https://www.joe0.com/2020/08/02/how-to-sync-fitbit-data-to-google-spreadsheet-vs-2-aug-2020/

OLD VERSION (no longer works)

This method of synchronizing Google Spreadsheet with Fitbit data is based on the work of Simon Bromberg. It uses a new Fitbit OAuth2 and Google's OAuth2 authentication method (tested as of 18.March.2017). You can find more about the sync scripts here: https://github.com/simonbromberg/googlefitbit

So let's start.

Copy Interday.gs script

Visit following URL and put the content of the interday.gs script into your clipboard (CTRL: https://github.com/simonbromberg/googlefitbit/blob/master/interday.gs

Create a new Google Spreadsheet

As a first step, create a new Google spreadsheet, name it whatever you want and save it.

Add interday.gs script to Google Spreadsheet

Then go to 'Tools', select 'Script Editor' option:

Paste the contents of the interday.gs file into the script editor, overwriting whatever default function definition is already in there.

Then name, it should look something like this once you're done:

Save the document:

Now, return to your blank spreadsheet (you can close the script window) and press F5 to refresh the page. It'll take about 5 seconds after the refresh for the 'Fitbit' menu to show up at the top of the Google spreadsheet menu. This is where you'll find it:

Install OAuth2 library for Google Apps Script

Now go to 'Tools,' select 'Script Editor' again. We'll need to add the Oauth2 Google Script library to our spreadsheet. To do so, click Resources in the top menu, then select Libraries:

Then add the OAuth2.0 library by typing in the project key "MswhXl8fVhTFUH_Q3UOJbXvxhMjh3Sh48" and hitting the Add button:

Once done, select the newest version and development mode and press save. It should look like this:

Get the 'Script ID'

The past procedures required a to get a project's key by clicking on the 'Fitbit' menu inside the spreadsheet and clicking 'Setup.'

However, the new process no longer uses the Project Key, which is deprecated now.

Instead, we'll need to get a 'Script ID'. To find it, go to 'Tools/Script Editor' again and then select 'File/Project Properties':

Copy the text adjacent to 'Script ID' in the popup. We will need that in subsequent steps.

Authorize Fitbit Sync

Close the Script Editor and go back to your blank Google spreadsheet and select the FitBit menu and click on 'Setup':

A popup window will ask for Authorization:

Click on 'Continue' button and follow Google singing process under which you want to authorize the Fitbit syncing application on.

Then it will show you the permissions the application is requesting, click 'Allow'.

Then the 'Setup Fitbit Download' panel should appear. Just close it for now.

Setup a new Fitbit app at Dev.Fitbit.com

Now, go to https://dev.fitbit.com/ and either register a new account or login to your existing account.

Click on 'Manage My Apps' in the top menu and click on the 'Register a New App' option:

The next step is to fill up the application. You can use whatever data you wish, see the example of what I did.

These are the important parts:

- For the OAuth 2.0 application type option, select: 'Personal' option.

- Default access type should be set to: 'Read-Only'.

- The other important piece of data on the form is the Callback URL. Type in the following url: https://script.google.com/macros/d/YOUR_SCRIPT_ID/usercallback. Then replace YOUR_SCRIPT_ID in the URL with the Script ID we have gathered in the previous step.

This is what the filled up application should look like. Once done, just press the 'Save' button.

On the next page, Fitbit will ask you to Agree to the terms, and Register.

Do so, and you will be redirected to a page that contains your credentials.

Mark down your 'OAuth 2.0 Client ID' and your 'Client Secret' keys. The following two pieces of information:

Setup a Fitbit sync

Go back to your blank Google Spreadsheet and select 'Setup' from the 'Fitbit' menu.

Copy in the 'OAuth 2.0 Client ID' and the 'Client Secret' from the previous step. and your project key from step 3.

Select all the activities that you'd like to sync to your spreadsheet. You can select all of them or individual ones.

Then select the range for which to download the data. Just note, that you shouldn't try to download more than a couple months worth of data, Fitbit's API will not like you.

Click 'Save Setup' and the panel will disappear.

Authorize Fitbit

In your spreadsheet, click 'Authorize' from the Fitbit menu and a sidebar will show up on the right.

Click the word 'Authorize' in the sidebar.

A page will open up with the Fitbit login page. Log in to the Fitbit account you would like to download data from in the new window, authorize the application by clicking 'Allow', and then close the tab when it says "Success you can close this tab"

First Sync

Inside the Google Spreadsheet, click on the Fitbit menu and select the 'Sync' option:

The process of synchronization will start and once finished, it'll look something like this:


We're done, if everything worked, don't forget to leave me a comment.

Enjoy!