如何从Google Fitness REST API检索步数数据? [英] How do I retrieve step count data from Google Fitness REST api?

查看:302
本文介绍了如何从Google Fitness REST API检索步数数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我在Nexus 5上安装了Google Fit应用程序,因此它一直在跟踪我的步数和步行时间。我想通过Google Fitness REST api检索此信息(文档),但我可以不知道如何从REST API获取任何数据。



我使用OAuth 2.0操场成功列出dataSources,但没有任何示例尝试已经返回任何健身数据。我觉得我需要使用类似于DataReadRequest( Android SDK ),但我并未构建Android应用 - 我只想访问已由Google健身应用存储的健身数据。



甚至可以获取Google健身应用收集的数据?如果是这样,我如何使用REST api读取和聚合步数数据?解析方案

结果是答案在毕竟,文档。以下是请求的格式。



GET https://www.googleapis.com/fitness/v1/users/{userId}/ dataSources / {dataSourceId} / datasets / {datasetId}



唯一支持的 {userId} {dataSourceId}可能的值 $ me (带有身份验证)。

可通过运行不同请求



我错过的是 {datasetId} 并非真正的ID,你定义你感兴趣的时间范围。该变量的格式是 {startTime} - {endTime} ,其中时间自纪元开始以纳秒为单位。


Since I installed the Google Fit app on my Nexus 5 it has been tracking my step count and time spent walking. I'd like to retrieve this info via the Google Fitness REST api (docs) but I can't work out how to get any of that data from the REST api.

I've used the OAuth 2.0 playground to successfully list dataSources but none of the examples I have tried have returned any fitness data whatsoever. I feel like I need to use something similar to a DataReadRequest from the (Android SDK) but I'm not building an Android app -- I just want to access fitness data already stored by the Google Fit app.

Is it even possible to get the data gathered by the Google Fit app? If so, how can I read and aggregate step count data using the REST api?

解决方案

It turns out that the answer is in the docs after all. Here is the format of the request.

GET https://www.googleapis.com/fitness/v1/users/{userId}/dataSources/{dataSourceId}/datasets/{datasetId}

The only supported {userId} value is me (with authentication).

Possible values for {dataSourceId} are avaiable by running a different request.

The bit I missed was that {datasetId} is not really an ID, but actually where you define the timespan in which you are interested. The format for that variable is {startTime}-{endTime} where the times are in nanoseconds since the epoch.

这篇关于如何从Google Fitness REST API检索步数数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆