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

Updated on Friday, December 29, 2023

Comments Page 3

Return to post.

Comments

Robert Ellison

Hi Diedrich, I'd start by examining the JSON response. Are you getting anything at all for move minutes? Maybe it's some small difference in how it needs to be parsed.

Diedrich S

Hi Robert,

Thank you so much for putting this together! I do not program in Java, and have been wanting to extract some of my data from Google Fit that doesn't necessarily come with the data when doing a Google Takeout, so I really appreciate you putting together this post, it really was easy getting it up and running.

I was able to modify your script to also bring in the aggregated calories expended as well as the aggregated heart points. One data type I'd like to bring in, but it's not working is move minutes. I'd like to bring in the total move minutes from a day.

According to the API documentation (https://developers.google.com/fit/datatypes/aggregate), the data type and field of aggregated move minutes is the same as the instantaneous data type (https://developers.google.com/fit/datatypes/activity#move_minutes).

So long as I have the right dataTypeName and dataSourceId (I do, I found them here: https://stackoverflow.com/questions/41173213/getting-active-time-from-google-fit-rest-api), I should be able to bring in this data just like I did with calories and heart points. Unfortunately, something is wrong and it doesn't bring any move minute data into the google spreadsheet. I get all the other data, but not move minutes. The OAuth permission scope is the same for other activity data types: https://www.googleapis.com/auth/fitness.activity.read.

I've added in the following to the var request:

{

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

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

},

{

"dataTypeName" : "com.google.heart_minutes",

"dataSourceId" : "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes"

},

{

"dataTypeName": "com.google.active_minutes",

"dataSourceId": "derived:com.google.active_minutes:com.google.android.gms:merge_active_minutes"

}

I've also made these changes in the for loop:

var steps = -1;

var weight = -1;

var distance = -1;

var calories = -1;

var heartmin = -1;

var movemin = -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) {

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

}

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

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

}

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

calories = json.bucket[b].dataset[3].point[0].value[0].fpVal;

}

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

heartmin = json.bucket[b].dataset[4].point[0].value[0].fpVal;

}

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

movemin = json.bucket[b].dataset[5].point[0].value[0].fpVal;

}

sheet.appendRow([bucketDate,

steps == -1 ? ' ' : steps,

weight == -1 ? ' ' : weight,

distance == -1 ? ' ' : distance,

calories == -1 ? ' ' : calories,

heartmin == -1 ? ' ' : heartmin,

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

}

As mentioned before, all the other data, steps, weight, distance, calories, and heart minutes are pulled into the spreadsheet, just the move minutes are not brought in. I'm not sure what my mistake is.

Thanks!,

Diedrich

John Langstaff

Wow. I just want to, like, click on “Export”, pick a common file format, and tell it a destination, to get my data….Oh! It’s not _my_ data! It’s data I _gave_ them! Dopey my reasonably expectious me be!

Guga Alves

I've added new lines on my Metrics and Historic tabs to get data for 2023, but it is not working. I've already reset settings and authorized it again, but I can't get new data there... not sure what else I should do.

Robert Ellison

Yubin - follow the instructions near the end of the post for resetting authorization.

yubin

Thank you for good information. Thanks for completing all the steps.

However, when I try to load yesterday's data or load data from 60 days ago, "Error: Access not granted or expired." appears and no data is entered. How can I solve this?

Chris Chin

I'm not tech savvy and most blogs make my eyes roll over. Thanks for writing this up as it was super easy to follow even with Google changing the names of some of the functions you used. After going back and forth with the API bit, I got it working easily. Then I ran into the 90 day max history thing and found the workaround in the comments.

Thanks a bunch! I've been wanting to graph my weight over the past few years but Google Fit's app only shows you calendar years. This worked great.

Robert Ellison

I don't have this so no way to debug it. I think you'll probably need to post this in the Google forums and see if anyone there can help. Please post back if you find out.

Sebastian

Hi Robert,

I haven't seen anybody conquer the body fat percentage code.

In the API explorer there is no Data Source ID for the data name. It returns:

{

"dataSource": []

}

Where do you go from here?

Guga Alves

And if your want to format distance as Kilometers, change "distance = json.bucket[b].dataset[2].point[0].value[0].fpVal;" to "distance = (json.bucket[b].dataset[2].point[0].value[0].fpVal) / 1000;"

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.