Comments
Andrew, I'll try to provide some more sample code but probably won't have time until the weekend.
Hi Robert, thanks for the quick response.
I really want to have all historic data in a google sheet: specifically calories burnt per day, or activity level (steps or minutes) per day from back as early as 2015 when I started using the app.
When you say:
"You could pass a parameter into getSteps for the number of days ago and then loop through as much history as you need."
Could you be a bit more specific/step-by-step. This is my first ever project even opening up script editor.
Hi Andrew, for older data see the date logic at the top of getSteps (i.e. setDate(start.getDate()-1)). By changing the two -1 values to -2 you'd get the day before yesterday. You could pass a parameter into getSteps for the number of days ago and then loop through as much history as you need. For calories it looks like com.google.calories.expended is probably the right dataSourceId. See the previous couple of comments for a discussion of getting weight, this would be a similar adaptation.
Hi There,
I'm a total idiot with programming but was able to follow your steps. Thanks so much!
Is there a way I can get historical data and also data for calories burnt?
Regards,
Andrew
Hi Vinay, I just experimented with this and I think you need to make two changes. For dataSourceId you need derived:com.google.weight:com.google.android.gms:merge_weight and then when reading the weight it's in fpVal rather than intVal in the JSON response. I got this working with a modified copy of my existing script (I'm just doing a weight version, not attempting to read weight and steps at the same time). Hope this helps, good luck!
This script works for me but when I try to get weight data it fails in getting response.
I am using below for weight
"dataTypeName": "com.google.weight.summary",
"derived:com.google.step_count.delta:com.google.android.gms:merge_weight"
On the response line I get "datasource not found error" error
Thank you!!
Thank you so much for taking the time to write this up. Well done and I have my project up and running!
Very helpful, works great for me. Thanks for taking time to post this!!
Rob, you do need the Google Fit API to be enabled in the API console. I'm not clear if you've done this or not from the mention of not having a GCP account. If you happen to come back to this and need help feel free to email me at [email protected] and let me know where you're getting stuck.
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.