借助 Fitness REST API,您可以创建、获取和向数据集添加数据点。数据集表示来自特定数据源的一组数据点。
数据集由
Users.dataSources.datasets
资源。
向数据集添加点
本示例展示了如何将 10 个新的步数增量点添加到 之前是空数据集。此示例假定您已创建数据源 ,具体说明请参阅管理数据源。
- HTTP 方法
- 补丁
- 请求网址
https://www.googleapis.com/fitness/v1/users/me/dataSources/
derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001
/datasets/1397513334728708316-1397515179728708316- 请求正文
{ "dataSourceId": "derived:com.google.step_count.delta:1234567890:Example Manufacturer:ExampleTablet:1000001", "maxEndTimeNs": 1397515179728708316, "minStartTimeNs": 1397513334728708316, "point": [ { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397513365565713993, "originDataSourceId": "", "startTimeNanos": 1397513334728708316, "value": [ { "intVal": 8 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397513675197854515, "originDataSourceId": "", "startTimeNanos": 1397513530098955298, "value": [ { "intVal": 3 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397513764101240710, "originDataSourceId": "", "startTimeNanos": 1397513817073528237, "value": [ { "intVal": 6 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397513938674093579, "originDataSourceId": "", "startTimeNanos": 1397514015761859752, "value": [ { "intVal": 5 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397514106400006675, "originDataSourceId": "", "startTimeNanos": 1397514181893785805, "value": [ { "intVal": 4 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397514304850163634, "originDataSourceId": "", "startTimeNanos": 1397514356883524220, "value": [ { "intVal": 16 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397514518794639297, "originDataSourceId": "", "startTimeNanos": 1397514526864527756, "value": [ { "intVal": 13 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397514741275742506, "originDataSourceId": "", "startTimeNanos": 1397514626480314270, "value": [ { "intVal": 18 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397514813435152213, "originDataSourceId": "", "startTimeNanos": 1397514839292833196, "value": [ { "intVal": 17 } ] }, { "dataTypeName": "com.google.step_count.delta", "endTimeNanos": 1397515179728708316, "originDataSourceId": "", "startTimeNanos": 1397515170565969137, "value": [ { "intVal": 11 } ] } ] }
- 响应
响应为
200 OK
状态代码。响应正文包含数组 包含成功插入所有点的 JSON 表示法。- curl 命令
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X PATCH \ --header "Content-Type: application/json;encoding=utf-8" -d @addpoints.json \ "https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001/datasets/1397513334728708316-1397515179728708316"
获取数据集
此示例演示了如何获取数据集的内容。
- HTTP 方法
- GET
- 请求网址
https://www.googleapis.com/fitness/v1/users/me/dataSources/
derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001
/datasets/1397513334728708316-1397515179728708316- 请求正文
- 无。
- 响应
- 如果数据集存在,则响应为
200 OK
状态代码。响应 body 包含数据集的 JSON 表示法。 - Curl 命令
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X GET \ --header "Content-Type: application/json;encoding=utf-8" \ "https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001/datasets/1397513334728708316-1397515179728708316"