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

Updated on Friday, April 28, 2023

Comments Page 12

Return to post.

Comments

Rajat Anand

Hi.

This code works great. I deployed the code as a web app and am able to populate the History sheet when running the link in-cognito mode using same email to login as the email I used to make the sheet. I was curious to know if someone else uses this deployed link i.e. use some other email id for authorization. I tried that, it threw error Error: Access not granted or expired. (line 454, file "Service").

Can you help?

Robert Ellison

Hi Momo - yes, if the user signs into the sheet with their account and authorizes it will read their data. I wrote this as a means to get your own data and there are some considerations if you share with someone else, for instance if you give them edit permission to the sheet they will be able to see your secret API key in the script. Generally OAuth is designed for this kind of flow where a user can delegate access to a trusted app. Depending on what you're trying to build Google Sheets might not be the best tool.

momo

I am new here!

Can I use this code and the AOuth2 get someone's google fit data with his authorization ?

Could you give me some suggestions,Please? Thank you very much!

Mark

Thanks so much for this, worked first time flawlessly. Now to import the data into Grafana.

Thank you again for writing up such a detailed explanation of steps that were so easy to follow.

Robert Ellison

Dennis - try the API Explorer linked to in the post. It's pretty handy for finding the right IDs for your account. I don't have anything that provides body fat so can't check this directly.

Dennis

How can i add "com.google.body.fat.percentage.summary" ? I can't find the right dataSourceId

Robert Ellison

Jack - great, glad to hear it. Probably the problem with 60 days is not having enough data, try setting a smaller window. I don't have anything on heart rate. If anyone manages this please post!

Darren - I haven't seen duplicate rows recently but I have seen it happen. Looks like Apps Script maybe does an unexpected retry in some circumstances? If it's a problem it would be possible to check the last row in the sheet to see if the date is a duplicate or not.

Jack

Thanks Robert for all the help! Its getting there! It now works for me to pull just yesterday's data but the same error appears when I try to pull the past 60 days data. Would it be because I do not have yet 60 days worth of data?

On a separate note, one of the comments did try to write the script for heart rate, do you happen to have any updates regarding pulling both exercising Heart Rates as well as resting Heart Rates for this?

Your help is much appreciated!

Darren Wall

I've been running this script for about 6 months with minimal issues. I see multiple entries on 12th June having not messed with the scripts, has anyone else seen this?

Robert Ellison

Jack - that looks like it couldn't find the sheet. The script expects a sheet called Metrics for the daily update or History for the longer term pull. Make sure your spreadsheet is configured with the right sheets (or change the code if you want to call the sheets something else).

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.

Newsletter

Related

Average Server Response Time in Azure Metrics