1

HUAWEI Health Kit provides atomic data opening. After obtaining the user's authorization for the data, the application can access the sports health data through the interface, and perform operations such as adding, deleting, modifying, and checking user data, providing users with Sports and health data services. In this article, we summarize the typical authorization-related problems raised by developers and provide reference solutions, hoping to provide reference for other developers who encounter similar problems.

1. The Android App cannot evoke the Health Kit authorization. What is the reason for the HealthKitAuthResult result authorization failure statusCode: 6003?

"6003" is an error reported by the HMS Core SDK framework. When the certificate fingerprint verification-signature certificate fingerprint is incorrect, the error code 6003 will be returned. At this point, you need to follow the following 2 steps to check whether the signing certificate configured in the apk is correct.

Step 1. Check whether the correct certificate fingerprint is configured when applying for related services. Open the app's APK, unzip the "META-INF" folder, get the "CERT.RSA" file, and print the signature certificate information through the keytool -printcert -file META-INF/CERT.RSA command.

Step 2. Log in to AppGallery Connect, click "My Projects", select the project that needs to be operated, enter the project page and select the application, and then check whether the information configured in "SHA256 Certificate Thumbprint" in "Project Settings > General" is the same as that in Step 1. Fingerprints match.

For more HMS Core SDK framework error codes, please refer to the official website documentation

2. The error code 50005 "Authentication unknown error" is returned when the API is called. What is the reason?

Calling the client-side interface returns an error code of 50005. Please check the following:

(1) Before authorizing the operation, please ensure that the review of the sports health data you applied to read/write in the alliance card has passed.

(2) When the application pulls up the authorization page, the data displayed to the user for optional authorization needs to be included in the sports health data approved by the alliance card.

(3) The user data that can be manipulated by the application is the intersection of the read/write permission of the data type approved by the alliance card and the read/write permission of the data type checked by the user on the authorization page.

(4) HMS will cache the Scope permission information for 24 hours. If this error occurs, it may be caused by caching.

Clear the cache and data of "HMS Core" in the "App Management" of the mobile phone.

Go to "HUAWEI ID > Privacy Center > Control Access to Your Account" to cancel the authorization of the app, then reopen the app to log in to the HUAWEI ID and apply for authorization.

3. When the token is obtained, it is reported as 20022 (invalid direct_uri). What is the general cause?

Error code 20022 indicates that the format check of redirect_uri failed. The following checks are recommended:

(1) When using redirect_uri to obtain tokens, the redirect_uri you fill in must be the same as the one you filled in in "Product Services > Account > Callback Address" in the application when you apply for account service - setting account service information.

(2) redirect_uri needs to be encoded by URLEncode.

Note: After the user agrees to the authorization on the authorization page, the OAuth authorization service returns the response value authorization code Code to the application through the callback address redirect_uri. At this time, the authorization code encoded by URLEncode is returned, which can be used directly. When using Postman request, when the body uses x-www-form-urlencoded, the code needs to be decoded before use, that is, URLDecode encoding; when the body is in raw format, the code can be used directly without decoding.

Authentication and Authentication Example Reference Document

For more information on HUAWEI ID REST error codes, please refer to the document

4. My app needs to obtain the user's exercise time, calorie consumption, pace, average heart rate and step count data during the last run. Do I need to apply for the heart rate data permission in the sports health data when applying for Health Kit? Or just apply for exercise record data permission? What permissions should I apply for Scopes in the code section?

If your app needs to read the data in the exercise record card on the Sports Health App, it first needs to understand that the exercise record data opening consists of two parts of permissions:

(1) Exercise record summary data permission

The name of the permission applied for by the alliance card: exercise record data > user exercise record data

Scope permission to read exercise records:

Android SDK access: Scopes.HEALTHKIT_ACTIVITY_RECORD_READ

REST access: https://www.huawei.com/healthkit/activityrecord.read (Scope permission URL)

Taking running exercise records as an example, when your application needs to obtain sampling statistics data types such as distance statistics, calorie statistics, and step count statistics in the user's running exercise records, since the sampling statistics data types are part of the summary data of exercise records, only You need to apply for the permission to read the user's exercise record data.

(2) Atomic sampling data permissions associated with motion records

OAuth permissions corresponding to each atomic sampling data type are required.

Taking running exercise records as an example, if your application needs to obtain the GPS details, cadence details, altitude details and other data associated with the running exercise records, it also needs the OAuth permission corresponding to each atomic sampling data type.

The atomic sampling data type corresponds to the permission name and Scope permission applied for by the alliance card, please refer to the data type chapter of the alliance document: Android SDK access to REST access

Learn more details>>

Visit the official website of Huawei Sports Health Service Alliance

Visit the official website of Huawei Developer Alliance

Get development guidance documents

Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee

Follow us to know the latest technical information of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙原生应用,和开发者共同成长。