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

Updated on Friday, April 28, 2023

Comments Page 9

Return to post.



Ah that was it...thanks!

Robert Ellison

Mike, sounds like it's not loading the sheet. It expects the sheet to be called Metrics. If it has a different name then this is the error I'd expect.


Thank you for putting this together. I worked through all of the authorization issues, but now I'm getting "TypeError: Cannot read property 'appendRow' of null". I tried outputting the json to the Logger and it seems to be blank. Am I missing some required config? I'm using your code and the only thing I've updated is the Client ID and Secret.

Thanks again,


Robert Ellison

John - From your project in APIs and Services (Google Developer Console) click Credentials in the left menu, then the edit icon next to your OAuth2.0 Client, you can add the redirect URI at the bottom of that screen.

Robert Ellison

Hi Alexander, glad you figured out the history. For the authentication problem please follow the instructions in the second to last paragraph of the post to reset your credentials and try again.


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).

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