Submit weight information / distance through the Google Fit REST API

Deadly 提交于 2019-12-10 23:13:45

问题


I've been building a fairly simple app for a few weeks now, that pushes activity from my Fitbit Flex tracker to Google Fit. It's all very simple: it has created data sources, and uses those to push the last hour's calorie count, step count and distance to Google Fit. It also pushes my weight, should I log it using the Fitbit app.

Every hour, it pushes these three metrics in three different data sets, each with a single data point. For example: from 10:00 to 10:59, 451 steps. This works pretty well for all three of these metrics.

Once a day, a data set with a range of 00:00 to 23:59 sends my weight to Google Fit. This data set has one data point as well.

This system seems to work well enough for my step count and my calorie count. It is not perfect, because my step count is without any associated activities. But Google Fit receives the data successfully and stores it.

However, Google Fit does not seem to pick up on my reported weight. Nor does Google Fit seem to remember the distance as I submit it.

The data types I am using are:

  • com.google.calories.expended
  • com.google.distance.delta
  • com.google.step_count.delta
  • com.google.weight

The source code of my application is on Github: https://github.com/JC5/fitsync

Any tips or tricks? Is this something I could use the REST API for?


回答1:


Yes. This question lead me in the right direction. As it turns out, the field types I am using are instantaneous field types (see above). They are measured at one single moment in time only. The opposite would be an aggregated field type.

My weight is measured right here and right now and the value is not aggregated over a day or a week but a single instantaneous measurement. At this exact moment, I weight 82.1 kg.

So, when you create a dataset with a single datapoint (which is what you need to send such an instantaneous field type to Google), you must make sure the start time and the end times are the same. After all, it would not be a correct entry if it wasn't instantaneous.

The data set I sent to Google Fit, which registered correctly in Google fit, is the following:

{
   "minStartTimeNs":1462358894000000000,
   "maxEndTimeNs":1462358894000000000,
   "dataSourceId":"your-data-id",
   "point":[
      {
         "dataTypeName":"com.google.weight",
         "originDataSourceId":"",
         "startTimeNanos":1462358894000000000,
         "endTimeNanos":1462358894000000000,
         "value":[
            {
               "fpVal":81.2
            }
         ]
      }
   ]
}

The distance metric has not registered yet, but there might be other undocumented features there.



来源:https://stackoverflow.com/questions/36997303/submit-weight-information-distance-through-the-google-fit-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!