【问题标题】:Google Fit REST API: get calories burned per activityGoogle Fit REST API:获取每次活动消耗的卡路里
【发布时间】:2016-09-18 17:42:39
【问题描述】:

我可以使用这段代码(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
        } 
    })

这是所有活动类型消耗的卡路里。如何只为踏步活动消耗卡路里?

【问题讨论】:

  • 更新:我应该添加bucketByActivityType: { activityDataSourceId: 'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps' } 吗?我不知道这种存储桶类型是否可以一起使用。
  • 您可以参考这个链接:stackoverflow.com/questions/37820404/…

标签: node.js rest google-fit


【解决方案1】:

回答有点晚,但这可能会有所帮助,将其用于正文:

{
  "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": {}
}

这将以活动桶的形式返回给定持续时间内的卡路里数据,即跑步时,会有一个桶,步行时会有另一个。响应看起来像这样:

{
    "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"
        },
        . . . .
}

您可以在此处找到活动类型列表:https://developers.google.com/fit/rest/v1/reference/activity-types

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多