首页 > 解决方案 > 我们如何使用 Google Fit rest API 获取当天的实时步数?

问题描述

在使用 Google Fit Rest API 进行健身活动时,它为我提供了前几天的数据以及适当的步数,但无法提供当天的计数。即使在我的手机中,Google Fit 同步过程也正常运行,并且我的互联网运行良好。

如果我强制同步(手动),那么它可以开始提供当天的步数和其他活动数据。否则,只能显示 9 点(或每日第一个同步周期)之前的数据。之后,它只能在 API 响应中以相同的时间范围更新第二天的步数。

下面我分享了带有所需参数的 API 详细信息:

HTTP方法:POST

请求网址:https ://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

请求正文:

{
  "aggregateBy": [{
    "dataTypeName": "com.google.step_count.delta",
    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1559154600000,
  "endTimeMillis": 1559241000000
}

回复 :

{
 "bucket": [
  {
   "startTimeMillis": "1559154600000",
   "endTimeMillis": "1559241000000",
   "dataset": [
    {
     "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:aggregated",
     "point": [
      {
       "startTimeNanos": "1559181787309598125",
       "endTimeNanos": "1559183772877349957",
       "dataTypeName": "com.google.step_count.delta",
       "originDataSourceId": "raw:com.google.step_count.cumulative:Realme:RMX1833:355d9abc461f5254:STEP_COUNTER",
       "value": [
        {
         "intVal": 233,
         "mapVal": []
        }
       ]
      }
     ]
    }
   ]
  }
 ]
}

目前,它只能显示从早上算起的 233 步,而 Google Fit 应用程序显示了 4674 步。如何获得与 Google Fit App 可以显示的相同的数字?

在此处输入图像描述

标签: restgoogle-fitgoogle-playground

解决方案


推荐阅读