HUAWEI Health Kit provides a REST API interface for third-party ecological applications, through which the database can be accessed to provide users with sports health data services. In the actual integration process, developers may encounter various problems. Here we share and summarize typical problems, hoping to provide reference for other developers who encounter similar problems.
1. After registering the subscription notification capability, the connectivity check fails
After registering as a subscriber, when testing the connectivity check callback notification address, the message "Connectivity check failed, connectivity check response is not 204" is displayed.
Cause Analysis:
If the callback notification address can be accessed, the developer needs to confirm whether the HTTP status code of the subscribed callback notification address is 204, otherwise 404 will be returned to indicate that the connectivity check of the callback address fails.
Refer to Subscription Data Documentation
solution:
Check if the link is available and if the status code returned is 204.
2. The total number of steps returned by the sampling data statistics interface is inconsistent with the total calculated by yourself after obtaining the detailed data of the number of steps
Use the sampling data statistics query interface to obtain the total number of steps
Statistics query interface: https://health-api.cloud.huawei.com/healthkit/v1/sampleSet:polymerize
Request parameters:
{
"polymerizeWith": [
{
"dataTypeName": "com.huawei.continuous.steps.delta"
}
],
"endTime": 1651809600000,
"startTime": 1651766400000,
"groupByTime": {
"groupPeriod": {
"timeZone": "+0800",
"unit": "day",
"value": 1
}
}
}
The final number of steps returned is 7118
Use the sample data detail query interface to obtain the step count details and calculate the sum
Detailed query interface: https://health-api.cloud.huawei.com/healthkit/v1/sampleSet:polymerize
Request parameters:
{
"polymerizeWith": [
{
"dataTypeName": "com.huawei.continuous.steps.delta"
}
],
"endTime": 1651809600000,
"startTime": 1651766400000
}
The total number of steps calculated from the returned result is 6280
It can be seen from the data that under the premise of the same time period, the total number of steps returned by the sampling data statistics interface is inconsistent with the sum calculated based on the details of the number of steps.
Cause Analysis:
It is caused by the different mechanisms of detailed data and statistical data. Detailed data and statistical data are reported separately. Due to various reasons, detailed data may be lost or delayed, resulting in an inability to match the two data completely.
Secondly, when the data of one day is counted, when the aggregation conditions are the following parameters (see the figure below), the reported statistical data is returned, not the data calculated from the detailed data.
solution:
When sampling data statistics query, aggregate by time, pass in the groupByTime parameter, and set the duration parameter in groupByTime.
Request parameters:
{
"polymerizeWith": [
{
"dataTypeName": "com.huawei.continuous.steps.delta"
}
],
"endTime": 1651809600000,
"startTime": 1651766400000,
"groupByTime": {
"duration": 86400000
}
}
The final result returned is 6280, which is consistent with the sum calculated based on the step details.
3. Error code 403, error message "Insufficient Permission: Request had insufficient authentication scopes."
Cause Analysis:
403 is the request rejected, mainly because the scopes permission is insufficient, resulting in the rejection of the request.
solution:
(1) Check whether the relevant permissions have been applied for in the alliance card.
(2) Check whether the requested authority has been passed in during authentication and authentication, and whether the authorization has been approved on the authorization page.
Whether the requested permission is passed in during authentication
Whether permission is checked in the authorization interface
4. Error code 400, error message "Insufficient Permission: Request had insufficient authentication scopes."
Case: Query the sample data details of the number of steps
Parameter Description:
Access Token: Generated according to the code of the first authentication and authentication.
The time of the first authentication (the time when the code is generated for the first time): around 8:00 a.m. on May 7, 2022.
Start time of collecting data:
Start time: 2022-05-06 00:00:00 (1651766400000)
End time: 2022-05-06 12:00:00 (1651809600000)
For specific requests, see the figure below:
Response result:
Cause Analysis:
When querying data, for the protection of user data, developers are only allowed to query data after user authorization. If you need to query the data before the user's authorization, the developer needs to obtain the authorization of the "read historical data" permission. If the user does not grant this permission, if the start time set by the developer when querying data is earlier than the user's authorization time, then The start time will be automatically corrected to the time of the user's first authorization, which will result in a query error (code: 400, message: "Invalid startTime or endTime.") or only the data after the user's authorization time can be queried, which is the same as the set start time. Times are inconsistent.
Take the example in the question as an example, since the user has not granted the permission to "read historical data", if the start time is May 6th and the first authorization time is May 7th, the start time will be automatically corrected to the first authorization time, that is, May 7, which causes the corrected start time to be later than the end time, so the error code 400 is returned, and the error message "Invalid startTime or endTime." is returned.
solution:
(1) Check whether the "Read Historical Data" permission has been applied for on the Health Kit Alliance Card, which is visible in the server application
(2) When generating the authorization code code, add the "https://www.huawei.com/healthkit/historydata.open" permission to the scope, so that users can grant "read historical data" to the app after logging in to the HUAWEI ID.
Data queried after authorization:
Learn more details>>
Visit the official website of Huawei Sports Health Service Alliance
Visit Huawei Sports Health Scenario Solution
Obtain the development guidance document of Huawei Sports Health Service
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。