我们如何使用Google Fit rest API获取当前当天的实时步数?

时间:2019-05-30 10:57:52

标签: rest google-fit google-playground

使用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可以显示的数字相同的数字?

enter image description here

0 个答案:

没有答案