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

Updated on Friday, April 28, 2023

Comments Page 6

Return to post.


Rajat Anand

commenting datasourceid worked for me for getting heart rate data.


"dataTypeName": "com.google.heart_rate.bpm"

///"dataSourceId": "derived:com.google.heart_rate.bpm:com.google.android.gms:heart_rate_bpm"



There was an earlier question about converting weight from kg to lb in the script. I see that I can add weight = weight * 2.205; But I'm unsure where to add that.

Austin M Robertson

I was having trouble and getting an Error 403 message when I tried to authorize. To fix the problem make sure you add your google account as a test user on the OAuth Consent screen.

Robert Ellison

Alex, you need to add the scope for calories to the .setScope call. Use the API explorer to find this. You will probably need to reauthorize the script again after adding the scope.


That's worked. Thanks Robert!

I didn't need distance, and instead wanted calories burnt so I have adapted the script to the below. However, it isn't pulling calories burnt. it is still getting step count and weight though.

var request = {

"aggregateBy": [


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

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



"dataTypeName": "com.google.weight.summary",

"dataSourceId": "derived:com.google.weight:com.google.android.gms:merge_weight"



"dataTypeName": "com.google.calories.expended",

"dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:from_activities"


Any ideas? THanks.

Robert Ellison

Alex, try following the steps to revoke access and reset the script. If that doesn't help then post back.


I've followed all the steps and encountered no problems. I've authorised the sheet/script to pull my Google Fit data but when I do via the 'Get metrics' option in the menu on sheets, the script inputs a date under the 'Date' column but then there's no data under Steps, Weight or Distance.

Any ideas?

Looking in Google Fit, I can see the data is there, but it just isn't pulling.


Hey Robert--I was able to parse out date from datetime and also make the kg to lb conversion pretty easily. Getting data for day 0 is where i was stumped but your comment helped me fix that, as well. I appreciate your time, sir! Thanks again.

Robert Ellison

Hi, Glad to hear you're finding this useful.

As written the script pulls a full day of data so I'm not sure how useful the date vs time thing is. The date passed to the sheet has a set of properties like getHours() the should allow you to break it down in any way you need.

Converting weight is easy - before writing to the sheet add:

weight = weight * 2.205;

To get data for today change the two 1s to 0s in the call to getMetricsForDays() near the top of the script. The code will create a new row each time to call it so you could do this several times a day to get updates or you could delete the last row if it has the same date and then add the latest data depending on what you're trying to achieve.


Robert--to parrot many here, thank you for your hard work. I had one hiccup where I had to add my own email address as a 'test user' before I could authenticate but that could have been due to being signed in to two Google accounts within Chrome while I was working or another step I may not have followed to the letter. In no time at all, I worked through that and populated all my data.

I'm trying to accomplish a few things and am running into some issues. (1) I'd like to split DATETIME into two separate columns DATE and TIME [does the API allow for that?] (2) I'd like to return weight in lb as opposed to kg. In Sheets I can '=CONVERT(C2,"kg","lbm")' but was wondering if I can have the script return that without converting after the fact? (3) Finally, I'd like the script to grab the 'latest' measurements (i.e. day 0) so that if I weighed in this morning and then viewed the sheet at lunch I can see 'today's' numbers. I can easily change the trigger timing, but not sure how to adjust the script to just call yesterday vs. "latest".

Your awesome walk-through has allowed me to chart blood ketones (mmol/L) against daily weight from my WiFi enabled scale and have proved immensely helpful in achieving my health goals. Thank you again!

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.

I Thought He Came With You is Robert Ellison's blog.



Average Server Response Time in Azure Metrics