“API 规范”部分详细概述了与平台集成所必需的技术组件,包括授权范围、数据类型定义和端点结构。此 API 代表了旧版 Fitbit Web API 的战略演变,它基于现代基础架构重建,以确保更稳定、更一致的开发者体验。
范围
您必须更新授权请求,才能使用 Google Health API 范围。 这些范围定义了您的应用是否支持读取或写入操作。请勿使用应用不需要的范围。如果应用的设计发生变化,您随时可以添加更多范围。
Google Health API 范围是一个 HTTP 网址,以 https://www.googleapis.com/auth/googlehealth.{scope} 开头。例如,https://www.googleapis.com/auth/googlehealth.activity_and_fitness.writeonly。
范围映射
下面介绍了 Fitbit Web API 范围如何映射到 Google Health API 范围:
| Fitbit Web API 范围 | Google Health API 范围 |
|---|---|
| activity | .activity_and_fitness.readonly
.activity_and_fitness.writeonly |
| blood_glucose | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| cardio_fitness | .activity_and_fitness.readonly
.activity_and_fitness.writeonly |
| electrocardiogram | .ecg.readonly
|
| heartrate | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| irregular_rhythm_notifications | .irn.readonly
|
| location | .location.readonly
|
| nutrition | .nutrition.readonly
.nutrition.writeonly |
| oxygen_saturation | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| profile | .profile.readonly
.profile.writeonly |
| respiratory_rate | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| settings | .settings.readonly
.settings.writeonly |
| sleep | .sleep.readonly
.sleep.writeonly |
| temperature | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| weight | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
数据类型
下面列出了 Google Health API 数据类型及其与 Fitbit Web API 的映射方式。
| Fitbit Web API 数据类型 | Google Health API 数据类型dataType |
|---|---|
| 活动消耗卡路里数 | 活动消耗能量active-energy-burned
|
| 活跃区间分钟数 | 活跃区间分钟数active-zone-minutes
|
| 包含用户活动级别的变化 | 活动级别activity-level
|
| 海拔 | 海拔altitude
|
| 血糖 | 血糖blood-glucose
|
| 体脂 | 体脂body-fat
|
每个心率区间内的 caloriesOut |
心率区间内的卡路里数calories-in-heart-rate-zone
|
| 温度(核心) | 核心体温core-body-temperature
|
| HRV 摘要 | 每日心率变异性daily-heart-rate-variability
|
| SpO2 摘要 | 每日血氧饱和度daily-oxygen-saturation
|
| 静息心率 | 每日静息心率daily-resting-heart-rate
|
| 体表温度 | 每日睡眠温度推导值daily-sleep-temperature-derivations
|
| 距离 | 距离distance
|
| 心电图 (ECG) | 心电图 (ECG)electrocardiogram
|
| 已录制的活动 | 锻炼exercise
|
| 楼层数 | 楼层数floors
|
| 食品 | 食品food
|
| 食品测量单位 | 食品测量单位food-measurement-unit
|
| 心率 | 心率heart-rate
|
| HRV 日内 | 心率变异性heart-rate-variability
|
| 心律不齐通知 (IRN) | 心律不齐通知irregular-rhythm-notification
|
| 饮食日志 | 营养日志nutrition-log
|
| SpO2 日内 | 血氧饱和度oxygen-saturation
|
| 用户跑步时的最大摄氧量值 | 跑步最大摄氧量run-vo2-max
|
| 活动时间序列分钟数(久坐) | 久坐不动时间段sedentary-period
|
| 睡眠 | 睡眠sleep
|
| 步骤 | 步骤steps
|
| 活动时间序列游泳划水次数 | 游泳长度数据swim-lengths-data
|
活动 caloriesOut |
总卡路里数total-calories
|
| 最大摄氧量值 | 最大摄氧量vo2-max
|
| 重量 | 重量weight
|
端点
REST 端点对所有数据类型采用一致的语法。
- 服务端点:基本 HTTP 网址更改为 https://health.googleapis.com。
- 端点语法:Google Health API 支持的 端点数量有限,大多数受支持的数据类型都可以使用这些端点。这为所有数据类型提供了一致的语法,并使端点更易于使用。
- 用户标识符:应在 端点语法中指定用户 ID 或 me。使用 me 时,系统会从访问令牌推断出用户 ID。
示例:以下示例展示了使用 Google Health API 调用的 GET Profile 端点
GET https://health.googleapis.com/v4/users/me/profile
端点映射
如需查看可用数据类型及其支持的 API 方法的列表,请参阅 Google Health API 数据类型 表。
| Fitbit Web API 端点类型 | Google Health API |
| GET(日志 | 摘要 | 每日摘要),用于请求单日数据 | dailyRollup 方法,其中 windowSize = 1 天 |
| GET(日内),用于请求精细数据 | list 方法 |
| 按日期或时间间隔 GET(时间序列) | rollUp 或 dailyRollUp 方法,包括日期范围 |
| GET(日志列表) | list 方法 |
| 创建和更新日志 | patch 方法 |
| 删除日志 | batchDelete 方法 |
| GET Profile | users.getProfile 返回用户的具体信息
users.getSettings 返回用户的单位和时区 |
| UPDATE Profile | users.updateProfile 修改用户的具体信息
users.updateSettings 修改用户的单位和时区 |
| 获取用户 ID | users.getIdentity 返回用户的 Fitbit 旧版用户 ID 和 Google 用户 ID。 |
| 获取设备 | users.pairedDevices 返回已配对设备的列表 |
| 创建订阅 | projects.subscribers.subscriptions.create 手动创建 订阅 |
| 删除订阅 | projects.subscribers.subscriptions.delete 删除 订阅 |
| 获取订阅列表 | projects.subscribers.subscriptions.list 列出所有 订阅 |