You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Fit API获取Move Minutes Count与步行时长数据?

解决Google Fit Move Minutes Count与步行时长导出问题

1. 确认正确的数据类型标识符

  • Move Minutes Count对应的数据类型确实是com.google.active_minutes,但需注意聚合时的数据源范围,直接指定dataTypeName即可,但要确保权限覆盖该类数据。
  • 步行时长需要单独请求com.google.duration数据类型,且必须筛选步行活动的数据源:活动类型枚举值为7(对应步行),数据源ID可使用derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments。

2. 调整聚合请求参数

在请求的aggregateBy数组中分别配置两个数据类型的规则,同时添加步行活动过滤器。示例代码片段如下:

// 聚合规则配置
const aggregateBy = [
  // Move Minutes Count
  { dataTypeName: 'com.google.active_minutes' },
  // 步行时长
  {
    dataTypeName: 'com.google.duration',
    dataSourceId: 'derived:com.google.duration:com.google.android.gms:merge_activity_segments'
  }
];

// 步行活动过滤器
const activityFilter = {
  dataSourceId: 'derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments',
  activityType: 7 // 枚举值7代表步行
};

// 完整请求体
const requestBody = {
  aggregateBy: aggregateBy,
  bucketByTime: { durationMillis: 86400000 }, // 按天聚合
  startTimeMillis: startDate.getTime(),
  endTimeMillis: endDate.getTime(),
  filter: activityFilter
};

3. 检查权限配置

确保你的OAuth 2.0授权范围包含https://www.googleapis.com/auth/fitness.activity.read——这是读取活动类数据(包括active minutes和步行时长)的必要权限,仅靠步数、卡路里的权限无法访问这类数据。

4. 正确解析响应数据

  • com.google.active_minutes的响应中,value数组内的intVal字段即为Move Minutes的总分钟数。
  • com.google.duration的响应中,value数组内的intVal是毫秒数,需除以60000转换为分钟数。

5. 拆分请求避免冲突

如果同时聚合多个数据类型出现异常,可以拆分两个独立的API请求:一个单独获取com.google.active_minutes,另一个带步行过滤器获取com.google.duration,处理完结果后再统一写入Google Sheet。

内容的提问来源于stack exchange,提问作者THORNADOR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 19:43:21