「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_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 |
| 心電圖 | .ecg.readonly
|
| 心率 | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| irregular_rhythm_notifications | .irn.readonly
|
| 位置 | .location.readonly
|
| 營養學 | .nutrition.readonly
.nutrition.writeonly |
| oxygen_saturation | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| 資料 | .profile.readonly
.profile.writeonly |
| respiratory_rate | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| 設定 | .settings.readonly
.settings.writeonly |
| 睡眠 | .sleep.readonly
.sleep.writeonly |
| 溫度 | .health_metrics_and_measurements.readonly
.health_metrics_and_measurements.writeonly |
| 重量 | .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
|
| 心率變異度摘要 | 每日心率變異daily-heart-rate-variability
|
| 血氧濃度摘要 | 每日血氧濃度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
|
| 當日血氧濃度 | 血氧濃度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:端點語法中應指定使用者 ID 或 me。使用我時,系統會從存取權杖推斷 User-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 (Intraday),用於要求精細資料 | list 方法 |
| 依日期或間隔取得 (時間序列) | rollUp 或 dailyRollUp 方法,包括日期範圍 |
| GET (記錄清單) | list 方法 |
| 建立及更新記錄 | patch 方法 |
| 刪除記錄 | batchDelete 方法 |
| 取得設定檔 | users.getProfile 會傳回使用者的特定資訊
users.getSettings 會傳回使用者的單位和時區 |
| 更新個人資料 | users.updateProfile 可修改使用者的特定資訊
users.updateSettings 可修改使用者的單位和時區 |
| 取得使用者 ID | users.getIdentity 會傳回使用者的 Fitbit 舊版和 Google 使用者 ID。 |
| 取得裝置 | users.pairedDevices 會傳回已配對裝置的清單 |
| 建立訂閱項目 | projects.subscribers.subscriptions.create 會手動建立訂閱項目 |
| 刪除訂閱項目 | projects.subscribers.subscriptions.delete 刪除訂閱項目 |
| 取得訂閱清單 | projects.subscribers.subscriptions.list 會列出所有訂閱項目 |