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

Updated on Friday, April 28, 2023

Comments Page 13

Return to post.



Hi, seems like I am struggling when going back to the sheets. Keeps coming up with errors. I tried redoing all the steps again but am faced again with a new error :

TypeError: Cannot read property 'appendRow' of nullDetails

Any help is much appreciated!

Robert Ellison

Jack - yes, it will warn you if not approved by Google, safe to ignore.


Thanks Robert for the reply. When trying to activate it on google sheets, seems like it detects it as an unverified app. Is that normal?

Robert Ellison

Jack - the redirect URL? Make sure you haven't left the { } characters in. You want to replace that entire segment with the script ID from apps script.


Hi, I am having issues with the URL (only have a URI option). It states that "The request failed because one of the field of the resource is invalid." Is there any way to get around this?

Robert Ellison

Vishal, you shouldn't need to set any of that stuff up. You only need it if you're going to make a public facing app and need to get the consent screen approved by Google and you don't need that for this script.


Have question about following -

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.

This seems to be changed when I go to Consent screen in Google API Console. Its asking for more values than explained in above paragraph such as authorized domain, Application Homepage link , Application Privacy Policy link etc. Can you help?

Robert Ellison

Hi James, you shouldn't need to run the authorize script on a schedule. This should be run once when you need to get permissions. If your authorization is expiring run through the steps above to reset everything and try again (reset the script, remove authorization from Google Fit).

James Vondale

This is a great tool, however the 60 minute token is troublesome.

I run these scripts as schedules, however the "Authorize if needed" which fixes the issue has to be run manually. Is there a way to modify this so I can run this without having the click the sidebar?


Thank you a lot for this!! I tried measuring the heart rate too, but I can not seem to find the data source that goes with com.google.heart_rate.bpm. From your code I just edited a few things:

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.distance.delta",

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



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

"dataSourceId": "derived: com. google.heart_rate.bpm:com. google. android.gms:{I have no idea what to put here}"



and I added some other things here:

var steps = -1;

var distance = -1;

var heart = -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[1].point.length > 0) {

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


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

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



steps == -1 ? ' ' : steps,

distance == -1 ? ' ' : distance,

heart == -1 ? ' ' : heart]);



If I find anything I'll post another comment. I also wanted to help Mark, on november 11 he asked if anyone could share the code for measuring the heart rate.

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