HUAWEI Health Kit allows third-party ecological applications to access the database through the REST API interface after obtaining user authorization, read the sports health data opened by Huawei and ecological partners, or write the data to the HUAWEI Sports Health Service, providing users with More personalized health improvement services. For example, sports apps can read the heart rate, steps and other exercise data of Huawei users after obtaining the authorization code, and finally provide users with health advice.
1. Apply for account service and apply for sports health service
Health Kit requires user login and authorization. You need to apply for an account service first. You can create an application while applying for an account service, or you can activate an account service for an already created application. After the creation is successful, you can view the created application in the account service list. Click the entry to view the detailed information as shown in the figure below. The APP ID, APP SECRET and callback address will be used later.
2. Get the authorization code
Compared with other Kit REST APIs, Health Kit needs to obtain an authorization code before using it. After logging in to a HUAWEI ID, the authorization code is obtained. There is an additional step for obtaining the authorization code.
The development guide gives a detailed introduction to the authorization code login. There are four required fields: client_id, response_type, redirect_uri and scope. The client_id is the APP ID that is automatically generated after the application is successfully created . redirect_uri is the "callback address" filled in in the step of applying for an account service .
After the user enters the HUAWEI ID login authorization, the web browser will jump to the link corresponding to redirect_uri, and append the required authorization code as a parameter to the link.
Take a look at the sample request given on the official website. Open the above link in a computer or mobile browser, and the following HUAWEI ID login and authorization page will be displayed.
After the login authorization is successful, the browser will jump to the following link
The authorization code code that the interface needs to use is the string value of the request payload parameter code in the link.
It should be noted that the code in the console here is the string before urlencode encoding, and the code in the browser is the string after urlencode encoding.
In the subsequent steps, the value of the code before urlencode encoding is mainly used. (The code in the browser needs to be decoded by urlencode before use)
Next, you need to obtain access_token and refresh_token through the authorization code code obtained above.
Due to usage restrictions, the next steps can no longer be tested using the parameters of the official website demo, and you need to create your own application . Then pass in the parameters related to your own project, and repeat the above steps to obtain the authorization code code.
The relevant parameters of the created application can be found under " App Service " - "Account". The following is the information page of a created test application.
1. Use the authorization code to obtain AT
client_id, redirect_url should be the same as those used to obtain the authorization code code.
The code parameter is the value of the code before urlencode encoding.
The client_secret parameter is the APP SECRET in the above application information.
2. Refresh Token to get access_token
3. Use the obtained access_token to test the data-related API
Since we applied for the permission to obtain height and weight when we logged in and authorized above, we will test the interface for obtaining height data here.
Referring to the document link of "Querying the Latest Sampling Data", the test results of the postman request in the document are as follows:
The parameters in the Head: Authorization The value of the field is: Bearer+'space'+access_token value, in the form of: Bearer {access_token}, the value of x-client-id needs to be the same as the client_id used above.
The request parameter "dataTypeName": "com.huawei.instantaneous.body_weight" can be found in the data type - weight - atomic sampling data type:
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/latest-sampleset-0000001078273166
If you want to query multiple data at the same time, the request url example is as follows:
https://health-api.cloud.huawei.com/healthkit/v1/sampleSets/latestSamplePoint?dataType=com.huawei.instantaneous.body_weight&dataType=com.huawei.instantaneous.blood_glucose
After linking, you can splicing multiple dataType parameters.
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) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。