Export Google Fit Daily Steps, Weight and Distance to a Google Sheet

Updated on Friday, December 29, 2023

Comments Page 11

Return to post.



Hello, Robert! i solved the first problem. Added the following lines:

function getHistory() {

getMetricsForDays(120, 140, 'History');

getMetricsForDays(60, 120, 'History');

getMetricsForDays(1, 60, 'History');

But the second problem remained.

Thanks for you work!



Hi, Robert!! Thank you for great work!!

1) I want to load data from history for the last 160 days.

When I try to specify more than 100 days, I get an error. I tried to take advantage of the comment by Nexis (on Thursday, April 18 2019) but I also get the error.

getMetricsForDays (, n, 'History'); where H <0.

2) And also, after setting up the trigger, I receive the error "Error: Access not granted or expired."

Thanks for you work!


John Cannon

Hi Robert,

Thanks for providing this info. I'm stuck on this paragraph:

Open the Google API Console. Create a new project and name it something like 'Google Fit Sheet'. From the Dashboard click Enable APIs and Services and find and select the Fitness API. Then go to Keys and create an OAuth Client ID. You'll be asked to create a consent screen, the only field you need to enter is the product name (i.e. 'My Fit App'). Then choose Web Application as the application type. You need to set the name and the authorized redirect URL. The redirect URL is https://script.google.com/macros/d/{SCRIPTID}/usercallback replacing {SCRIPTID} with the actual Script ID you made a note of above. After adding this make a note of the Client ID and Client Secret.

Specifically this sentence "Then choose Web Application as the application type. You need to set the name and the authorized redirect URL."

I don't see an option anywhere to choose Web Application and to set the redirect URL.

Thanks for any help!



Cool, thanks Robert!

Will try and see if I can reduce the interval.

Robert Ellison

Hi burningvortex99 - glad that it's working for you. I haven't tried to get more granularity on weight. The script at the moment requests the data for one day - you could reduce the interval and get the data per hour (or whatever you need).


Thanks, it is working as expected!

Just wanted to know if it is possible to fetch all the weights registered within a single day as well? Right now, only the daily average is fetched.


It's working.

Thank you Robert.

You are the best!

Robert Ellison

Sandy, sounds like you are nearly there. It's just returning one dataset now so change dataset[1] to dataset[0] in the remaining code that reads the weight value (two places to change).


I removed this from the script:


"dataTypeName": "com.google.step_count.delta",

"dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"




"dataTypeName": "com.google.distance.delta",

"dataSourceId": "derived:com.google.distance.delta:com.google.android.gms:merge_distance_delta"


var steps = -1;

var distance = -1;

if (json.bucket[b].dataset[0].point.length > 0) {

steps = json.bucket[b].dataset[0].point[0].value[0].intVal;


if (json.bucket[b].dataset[2].point.length > 0) {

distance = json.bucket[b].dataset[2].point[0].value[0].fpVal;


steps == -1 ? ' ' : steps,


distance == -1 ? ' ' : distance".

Then i removed the column B and D on the spreadsheet, in both sheet "Metrics" and "History".

So now i have, on both sheets, "Date" in A1 and "Weight" in B1. Nothing else.

New error: "TypeError: Cannot read property 'point' of undefined".

What did I do wrong?

I'm really sorry if I did something wrong, I'm not used to do script :( .

thank you again

Robert Ellison

Sandy - delete the step and distance related lines from the script - you'd need to do this in the request, where the values are parsed and then finally where they are written to the spreadsheet.

Add Comment

All comments are moderated. Your email address is used to display a Gravatar and optionally for notification of new comments and to sign up for the newsletter.