当前位置:AIGC资讯 > 数据采集 > 正文

【HMS Core】运动健康服务如何读取用户数据,是否需要创建数据采集器

 【问题描述】

运动健康服务如何读取用户数据,是否需要创建数据采集器?

【解决方案】

1、如果采用REST API,在获取历史健康数据时需要申请历史数据权限,可以根据以下链接查看读取历史数据相关说明:

https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/historydata-open-0000001209921350

2、读取用户在运动健康中的数据时,是不需要创建数据采集器的,直接调用相关查询接口即可。(创建数据采集器操作,一般用于写操作,比如写入心率告警健康记录,每写入一条数据都需要重新创建采集器。)

以读取用户步数数据的明细为例:

可以调用采样数据明细查询接口:

步数指南:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/steps-0000001177343435#section197671417152417

3、下面是以Postman做的请求,传入的相关参数可以见采样数据明细查询接口:

查询时,传入的时间段是需要读取的时间段,且一次传入的时间间隔不能超过30天。

请求示例

POST
https://health-api.cloud.huawei.com/healthkit/v1/sampleSet:polymerize
Content-Type: application/json
Authorization: Bearer ***
x-client-id: ***
x-version: ***
x-caller-trace-id: ***
{
 "polymerizeWith": [
   {
     "dataTypeName": "com.huawei.continuous.steps.delta"
   }
 ],
 "startTime": 1590700295000,
 "endTime": 1591018695000
}

响应示例

HTTP/1.1 200 OK
Content-type: application/json;charset=utf-8
x-health-app-privacy: 1
{
    "group": [
        {
            "startTime": 1590700295000,
            "endTime": 1591018695000,
            "sampleSet": [
                {
                    "dataCollectorId": "derived:com.huawei.continuous.steps.delta:com.huawei.hms.hihealth.service:merged",
                    "samplePoints": [
                        {
                            "startTime": 1590760340000000000,
                            "endTime": 1590760460000000000,
                            "dataTypeName": "com.huawei.continuous.steps.delta",
                            "originalDataCollectorId": "raw:com.huawei.continuous.steps.delta:101278501:huawei:mp:1234567890",
                            "value": [
                                {
                                    "fieldName": "steps_delta",
                                    "integerValue": 50
                                }
                            ]
                        },
                        {
                            "startTime": 1590760460000000000,
                            "endTime": 1590761060000000000,
                            "dataTypeName": "com.huawei.continuous.steps.delta",
                            "originalDataCollectorId": "raw:com.huawei.continuous.steps.delta:101278501:huawei:mp:1234567890",
                            "value": [
                                {
                                    "fieldName": "steps_delta",
                                    "integerValue": 60
                                }
                            ]
                        },
                        {
                            "startTime": 1590846740000000000,
                            "endTime": 1590846860000000000,
                            "dataTypeName": "com.huawei.continuous.steps.delta",
                            "originalDataCollectorId": "raw:com.huawei.continuous.steps.delta:101278501:huawei:mp:1234567890",
                            "value": [
                                {
                                    "fieldName": "steps_delta",
                                    "integerValue": 70
                                }
                            ]
                        },
                        {
                            "startTime": 1590846860000000000,
                            "endTime": 1590847460000000000,
                            "dataTypeName": "com.huawei.continuous.steps.delta",
                            "originalDataCollectorId": "raw:com.huawei.continuous.steps.delta:101278501:huawei:mp:1234567890",
                            "value": [
                                {
                                    "fieldName": "steps_delta",
                                    "integerValue": 80
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]}
 欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

更新时间 2023-11-08