0

I 'm having trouble with the GoogleFit API where I can get the steps back but I cannot get the Calories.

Here is the URL I am making a POST to :

https://fitness.googleapis.com/fitness/v1/users/me/dataset:aggregate

Here is the body in JSON:

{
  "aggregateBy": [{
    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:from_activities" 
  }],
  "bucketByTime": { "durationMillis":86400000 },
  "startTimeMillis" : 1617235200000,
  "endTimeMillis" : 1617287510000
}

Here is the response:

{
    "bucket": [
        {
            "startTimeMillis": "1617235200000",
            "endTimeMillis": "1617287510000",
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:aggregated",
                    "point": []
                }
            ]
        }
    ]
}
mick1996
  • 516
  • 9
  • 31

1 Answers1

2

I would suggest aggregating by data type rather than data source:

  "aggregateBy": [{
    "dataTypeName": "com.google.calories.expended" 
  }],

The streams like derived:com.google.calories.expended:com.google.android.gms:from_activities are a bit of an implementation detail.

  • Hi there, thank you very much for your response! I have made that change there to the body! Would you know how I could get the latest calories burned from the API as it is displayed on the app? Usually the number I receive from this `POST` is quite far off. I would be grateful if you could shed some light? – mick1996 Apr 14 '21 at 15:51
  • 1
    I'm afraid there are a few reasons they'd be different: one is that the app has more up-to-date data until it's synced. The other is that the app will return calories for time ranges that have no data, while the platform won't. That's a fairly confusing distinction, I agree.. – Graeme Morgan Apr 15 '21 at 16:07
  • Thank you for clarifying – mick1996 Apr 16 '21 at 17:56