📋 Export your Fitbit Data in a Google Spreadsheet
1. Overview
\[ \begin{array}{l} \textbf{You can automatically export Fitbit activity, sleep, or heart rate data --} \\ \text{into a Google Spreadsheet using Google Apps Script and Fitbit API.} \\ \textbf{This enables personal health dashboards, data backups, or analytics --} \\ \text{directly inside your Google Sheets.} \end{array} \]
2. Use Cases
- Daily step count, heart rate, or calories burned tracking
- Analyze sleep stages over time
- Visualize activity trends and generate health reports
- Sync Fitbit data into no-code platforms or automate insights
These use cases are helpful for fitness goals, wellness journaling,
or medical monitoring with personal data control.
3. Steps to Set Up Fitbit API Access
1. Go to https://dev.fitbit.com/apps and create a new app
2. Choose "Personal" app type for private use
3. Set callback URL to https://script.google.com/macros/d/YOUR_SCRIPT_ID/usercallback
4. Note your Client ID and Client Secret
5. Enable OAuth 2.0 (Authorization Code Grant Flow)
You’ll use this app to authenticate your Fitbit account and access your data securely.
4. Apps Script Example to Authorize Fitbit
// Add OAuth2 library to your project:
// Resources → Libraries → Add OAuth2 (Project Key: 1B...BD2)
function getFitbitService() {
return OAuth2.createService('fitbit')
.setAuthorizationBaseUrl('https://www.fitbit.com/oauth2/authorize')
.setTokenUrl('https://api.fitbit.com/oauth2/token')
.setClientId('YOUR_CLIENT_ID')
.setClientSecret('YOUR_CLIENT_SECRET')
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('activity sleep heartrate')
.setTokenHeaders({ 'Authorization': 'Basic ' + Utilities.base64Encode('YOUR_CLIENT_ID:YOUR_CLIENT_SECRET') });
}
function authCallback(request) {
const service = getFitbitService();
const authorized = service.handleCallback(request);
return HtmlService.createHtmlOutput(authorized ? "Success!" : "Denied");
}
function authorize() {
const service = getFitbitService();
if (!service.hasAccess()) {
const authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and approve access: ' + authorizationUrl);
} else {
Logger.log('You are already authorized.');
}
}
This script manages OAuth2 authentication to connect to your Fitbit account.
5. Script to Export Fitbit Data to Sheet
function exportDailySteps() {
const service = getFitbitService();
if (!service.hasAccess()) {
Logger.log("Authorize first by running authorize()");
return;
}
const today = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
const url = `https://api.fitbit.com/1/user/-/activities/date/${today}.json`;
const response = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + service.getAccessToken() }
});
const data = JSON.parse(response.getContentText());
const steps = data.summary.steps;
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.appendRow([today, steps]);
}
This appends the current day’s step count to your spreadsheet. You can schedule it with triggers.
6. Automating with Time-Based Triggers
function createTrigger() {
ScriptApp.newTrigger('exportDailySteps')
.timeBased()
.everyDays(1)
.atHour(7)
.create();
}
This will run the exportDailySteps() function daily at 7 AM automatically.
7. Conclusion
With Google Apps Script and the Fitbit API, you can bring your health data
directly into Google Sheets. It offers a private, flexible, and customizable
alternative to third-party dashboards.
You can extend it to log heart rate, calories, or sleep data and build powerful wellness trackers.