Comments
Sandy, sounds like you are nearly there. It's just returning one dataset now so change dataset[1] to dataset[0] in the remaining code that reads the weight value (two places to change).
I removed this from the script:
"{
"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"
}
var steps = -1;
var distance = -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[2].point.length > 0) {
distance = json.bucket[b].dataset[2].point[0].value[0].fpVal;
}
steps == -1 ? ' ' : steps,
,
distance == -1 ? ' ' : distance".
Then i removed the column B and D on the spreadsheet, in both sheet "Metrics" and "History".
So now i have, on both sheets, "Date" in A1 and "Weight" in B1. Nothing else.
New error: "TypeError: Cannot read property 'point' of undefined".
What did I do wrong?
I'm really sorry if I did something wrong, I'm not used to do script :( .
thank you again
Sandy - delete the step and distance related lines from the script - you'd need to do this in the request, where the values are parsed and then finally where they are written to the spreadsheet.
Hi,
thank you for the quick answer.
Yea, i have no distance in it.
I'm only interested to monitor my weight.
What should I do?
Thanks again
Hi Sandy, sorry that didn't work. I can think of two possibilities. The first is that you didn't authorize all the required scopes - seems unlikely but you could revoke access again and then check the consent screen carefully to make sure that all the scopes are granted. The other reason could be that your fit account doesn't have distance in it (that looks like the metric with the error). You could use the API Explorer to see which metrics are available. If I think of anything else I'll post back.
Hello Robert,
so I disconnected the script from google fit.
After on google sheets, from the google fit menu i did "reset settings", re authorized again from the link, authorization ok.
When I do "get metrics" i get the same error.
I really don't know what to do.
Could be that I'm running the script from my browser on my Pc?
Because on the google sheets app from my smartphone i have no menu, i did everything from my pc.
Am I missing something?
On my smartphone tho I installed google sheets app and cloud console.
Thank you for your patience
Robert, Thanks for pointing me in the right direction.
I found the dataTypeName here: https://developers.google.com/fit/datatypes/activity#heart_points
It's com.google.heart_minutes right?
I'll study your script to figure out how dataSourceId is used for the other metrics.
John, heart points would be a great add. I'll look at it the next time I need to update the script. If you want to take a crack at it use the API Explorer linked above to find the dataTypeName and dataSourceId to add to the list of metrics being fetched.
Sandy, it sounds like you don't have Google Fit authorized or it's in a bad state. Follow the instructions in the second to last paragraph of the post to reset and see if that fixes the problem.
Hello Robert,
thank you for your work.
I would like to ask you some help.
I followed your guide, authorization ok on the google sheets from the "Google Fit" menu.
But when i click on "get metrics from yesterday" i get back this error:
"Exception: Request failed for https://www.googleapis.com returned code 403. Truncated server response: { "error": { "code": 403, "message": "datasource not found or not readable: derived:com.google.distance.delta:com.google.android.gms:merg... (use muteHttpExceptions option to examine full response)"
My "Fitness API" is enabled and on the dashboard tells me 8 request with 100% error.
Client ID and Secret are right in the script, i double checked and I tried to copy past them again.
On the "OAuth consent screen" i just set the name "My Fit App"
My "OAuth 2.0 client" name is "Fit1" but I don't think this is related to the problem.
What am I missing?
Could you help me?
Thank you in advance
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.