0

I can get calories burned for some period with this code (Node.JS):

 request({
        method: 'POST',
        uri: 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
        headers: {
          'Content-Type': 'application/json;encoding=utf-8',
          'Authorization': 'Bearer ' + accessToken
        },
        body: {
          aggregateBy: [{
            dataSourceId: 'derived:com.google.calories.expended:com.google.android.gms:platform_calories_expended'
          }],
          bucketByTime: { durationMillis: (endTimeMillis - startTimeMillis) },
          startTimeMillis: startTimeMillis,
          endTimeMillis: endTimeMillis
        } 
    })

This is calories burned for all activity types. How to get calories burned for step activities only?

MatejMecka
  • 1,448
  • 2
  • 24
  • 37
beardmeaning
  • 232
  • 3
  • 14
  • Update: should I add `bucketByActivityType: { activityDataSourceId: 'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps' }` ? I don't know if this bucket types work together. – beardmeaning Sep 18 '16 at 17:58
  • You may refer on this link: http://stackoverflow.com/questions/37820404/google-fit-api-getting-calories-burned-per-activity – abielita Sep 24 '16 at 04:36

1 Answers1

0

A bit late to answer but this might be helpful, use this for the body :

{
  "aggregateBy": [{
    "dataTypeName": "com.google.calories.expended",
    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended"
  }],
  "startTimeMillis": (start time here in ms),
  "endTimeMillis": (end time here in ms),
  "bucketByActivityType": {}
}

This will return the calorie data in the given duration in buckets of activity i.e for running, there'll be one bucket, for walking there'll be another. Response looks something like this :

{
    "bucket": [
        {
            "dataset": [
                {
                    "dataSourceId": "(source ID)",
                    "point": [
                        {
                            "startTimeNanos": "(start time here in ns)",
                            "endTimeNanos": "(end time here in ns)",
                            "dataTypeName": "com.google.calories.expended",
                            "originDataSourceId": "(source ID)",
                            "value": [
                                {
                                    "fpVal": 725.9259809516077,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                }
            ],
            "activity": 0 -> Code  for "vehicle"
        },
        {
            "dataset": [
                {
                    "dataSourceId": "(source ID)",
                    "point": [
                        {
                            "startTimeNanos": "(start time here in ns)",
                            "endTimeNanos": "(end time here in ns)",
                            "dataTypeName": "com.google.calories.expended",
                            "originDataSourceId": "(source ID)",
                            "value": [
                                {
                                    "fpVal": 539.63464736938477,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                }
            ],
            "activity": 1 -> Code for "Biking"
        },
        . . . .
}

You can find the list of activity types here : https://developers.google.com/fit/rest/v1/reference/activity-types