当前位置:网站首页>[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service

[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service

2022-06-10 13:04:00 51CTO

Huawei ​ ​ Sports health services ​​(HUAWEI Health Kit) It provides for the tripartite ecological application REST API Interface , The database can be accessed through its interface , Provide users with sports and health data services . In the actual integration process , Developers may encounter various problems , Here we will share and summarize the typical problems , Hope to provide reference for other developers who encounter similar problems .


1. After registering the subscription notification capability , Connectivity check failed

After registering as a subscriber , When testing the connectivity check callback notification address , Tips “ Connectivity check failed , Connectivity check response is not 204”.

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ data

Cause analysis :

When the callback notification address is accessible , The developer needs to confirm the callback notification address of the subscription HTTP Whether the status code is 204, Otherwise it will return 404 Indicates that the callback address connectivity check failed . Reference resources ​ ​ Subscribe to data documents ​


Solution :

Check if the link is available , And whether the returned status code is 204.

2. The total number of steps returned by the sampling data statistics interface is inconsistent with the total number calculated by yourself after obtaining the step number detail data

use ​ ​ Sampling data statistics ​​ Query the interface to get the total number of steps

Statistical query interface :https://health-api.cloud.huawei.com/healthkit/v1/sampleSet:polymerize Request parameters :

      
      
{
"polymerizeWith": [
{
": 1651809600000,
"startTime": 1651766400000,
"groupByTime": {
"groupPeriod": {
"timeZone": "+0800",
"unit": "day",
"value": 1
}
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

The final returned number of steps is 7118

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ developer _02

use ​ ​ Sampling data details ​​ Query the interface to get the step details , And calculate the sum

Details 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
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

The total number of steps calculated according to the returned results is 6280 【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ developer _03

We can see from the data that , On the premise of the same time period , The total number of steps returned by the sampling data statistics interface is inconsistent with the total number calculated according to the step number details .

Cause analysis :

It is caused by different mechanisms between detailed data and statistical data . Detailed data and statistical data are reported separately , For various reasons , Details may be lost or delayed , As a result, the two kinds of data can not be exactly matched . secondly , When counting the data of a day , When the aggregation condition is the following parameters ( See the picture below ), The returned statistics are reported , Instead of data calculated through detailed data . 【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ developer _04

Solution :

Sampling data statistics query , Aggregate by time , Pass in groupByTime Parameters ,groupByTime Set in duration Parameters . Request parameters :

      
      
{
"polymerizeWith": [
{
"dataTypeName": "com.huawei.continuous.steps.delta"
}
],
"endTime": 1651809600000,
"startTime": 1651766400000,
"groupByTime": {
"duration": 86400000
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

The final result is 6280, Consistent with the sum calculated according to the step details .

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ developer _05

3. Error code 403, error message “Insufficient Permission: Request had insufficient authentication scopes.”

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ data _06

Cause analysis :

403 To reject a request , Mainly scopes Insufficient authority , Cause the request to be rejected .

Solution :

(1) Check whether the alliance card has applied for relevant permissions .

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ developer _07

(2) Check whether the requested permission is passed in during authentication , And whether consent authorization has been made on the authorization page . 【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ data _08

Whether the requested permission is passed in during authentication Whether permission is checked in the authorization interface

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ data _09

4. Error code 400, error message “Insufficient Permission: Request had insufficient authentication scopes.”

Case study : Query the sampling data details of steps Parameter description : Access Token: Based on the first authentication code Code generation . The time of the first authentication ( For the first time code Code time ):2022 year 5 month 7 The morning of 8 P.m. . Start time of data collection : Starting time :2022-05-06 00:00:00(1651766400000) End time :2022-05-06 12:00:00(1651809600000) Specific request , See the picture below :

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ Solution _10

In response to the results :

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ Solution _11

Cause analysis :

When querying data , For the protection of user data , Only developers are allowed to query data after user authorization . If you need to query the data before user authorization , Developers need to get “ Read historical data ” Authorization of authority , If the user does not grant this permission , If the start time set by the developer when querying data is earlier than the user authorization time , The start time will be automatically corrected to the time when the user first authorizes , This will result in query errors (code:400,message: “Invalid startTime or endTime.”) Or you can only query the data after the user authorization time , Inconsistent with the set start time . Take the example in the question , Because the user did not grant “ Read historical data ” Authority , At the start time 5 month 6 Japan , The first authorization time is 5 month 7 In the case of , The start time will be automatically corrected to the first authorization time , That is to say 5 month 7 Japan , This causes the corrected start time to be later than the end time , Therefore, the error code is returned 400, error message "Invalid startTime or endTime.".

Solution :

(1) Check Health Kit Whether the League card has applied for “ Read historical data ” jurisdiction , This permission is visible in the server application

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ Solution _12

(2) Generate authorization code code when , stay scope Add "https://www.huawei.com/healthkit/historydata.open" jurisdiction , The user can grant... To the application after logging in to the Huawei account “ Read historical data ”. Data queried after authorization :

【FAQ】 Sports health services REST API Summary of common problems and solutions during interface use _ Solution _13

Learn more >> visit ​ ​ The official website of Huawei Sports Health Service Alliance ​

visit ​ ​ Huawei sports health scenario solution ​

obtain ​ ​ Huawei sports health service development guidance document ​

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101233451281.html