目录

@hms.core.account.intimate (My Circle)

Module Overview

The @hms.core.account.intimate module provides the capability of obtaining information about My circle members. You can launch the My circle member selection page for users to manage and select My circle members. After a user selects a member, you can obtain the member's UnionID and OpenID corresponding to their HUAWEI ID, anonymous account, nickname, and avatar information. The obtained information can be used to display the member's profile and establish user association based on their UnionID and OpenID.

Constraints

  1. The My circle member picker is available only on phones and tablets.
  2. Currently, this capability is available only to HUAWEI IDs registered in the Chinese mainland.
  3. The avatars and nicknames obtained through the My circle member picker are visible only to the user who has selected the members and cannot be shared. If you need to share this information, you must comply with applicable laws and regulations.

Prerequisites

Before development, ensure that you have applied for the permission to obtain the My circle relationship list. If the permission is not granted, the My circle member picker API will return error code 1026900009, indicating that the app does not have the permission, and the My circle member picker cannot be launched.

After the permission is granted, you need to request a profile again and manually configure signing information.

Since: 26.0.0

Modules to Import

import { intimate } from '@kit.AccountKit';

IdType

Enumerates the ID types of a HUAWEI ID user.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.AuthenticationServices.HuaweiID.Intimate

Since: 26.0.0

Name Value Description
OPEN_ID 1 OpenID of a HUAWEI ID user. For details about the format requirements, please refer to Formats of OpenID and UnionID.
UNION_ID 2 UnionID of a HUAWEI ID user. For details about the format requirements, please refer to Formats of OpenID and UnionID.

IntimatesSelectionRequest

Defines the request for launching the My circle member picker. You can use this object as an input parameter.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.AuthenticationServices.HuaweiID.Intimate

Since: 26.0.0

Name Type Read-Only Optional Description
maxSelectionCount number No Yes Maximum number of friends and family members that can be selected. The value must be an integer within the range of [1,5]. The default value is 1, which means only one friend or family member can be selected.
onlySelectIntimateWithHuaweiID boolean No Yes

Indicates whether to obtain only friends and family members with HUAWEI IDs. The default value is true.

When the value is true, the friend and family member list displays a label for friends and family members with HUAWEI IDs. Those without HUAWEI IDs are also displayed in the list, but selecting them prompts a message that a HUAWEI ID must be linked. The returned data includes OpenIDs, UnionIDs, anonymous accounts of HUAWEI IDs, nicknames, and avatars of the friends and family members. Only HUAWEI IDs can be used to add friends and family members.

When the value is false, no labels are displayed for friends and family members in the list, and only their nicknames and avatars are returned. In this case, friends and family members can be added from contacts, using HUAWEI IDs, or manually.

idType IdType No No ID type of a HUAWEI ID user. Only IdType.UNION_ID and IdType.OPEN_ID are supported.
idValue string No No

UnionID or OpenID of a HUAWEI ID user. The value type is determined by idType, and the value cannot be empty.

The UnionID or OpenID can be obtained through the capability of sign-in with a HUAWEI ID, obtaining user information associated with a HUAWEI ID, HUAWEI ID sign-in panel component, or HUAWEI ID sign-in button component.

IntimatesSelectionResponse

Defines the response to the request for launching the My circle member picker.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.AuthenticationServices.HuaweiID.Intimate

Since: 26.0.0

Name Type Read-Only Optional Description
openID string No Yes

Unique identifier of the HUAWEI ID of a friend or family member in an app or atomic service. A user has different OpenIDs across apps. For details about the format requirements, please refer to Formats of OpenID and UnionID.

Return scenario: This property is returned only when onlySelectIntimateWithHuaweiID in the request parameter IntimatesSelectionRequest is set to true.

unionID string No Yes

Unique identifier of the HUAWEI ID of a friend or family member under a developer account. A user has the same UnionID in different apps of the same developer. For details about the format requirements, please refer to Formats of OpenID and UnionID.

Return scenario: This property is returned only when onlySelectIntimateWithHuaweiID in the request parameter IntimatesSelectionRequest is set to true.

anonymousAccount string No Yes

Anonymous account returned based on the HUAWEI ID entered by the user when adding a friend or family member.

Return scenario: This property is returned only when onlySelectIntimateWithHuaweiID in the request parameter IntimatesSelectionRequest is set to true.

avatarUri string No No

Friend or family member avatar link, which becomes invalid immediately after the friend or family member updates the avatar. To ensure that the avatar can be properly displayed, it is advised to download and save the avatar before using it. This prevents service processes from being affected due to invalid avatar links.

Example format: https://xxx/xxx.

nickname string No No Nickname of a friend or family member. The value contains 1 to 256 characters.

IntimateErrorCode

Enumerates error codes of APIs related to the My circle feature.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.AuthenticationServices.HuaweiID.Intimate

Since: 26.0.0

Name Value Description
ACCOUNT_NOT_LOGGED_IN 1026900001 The user has not signed in with their HUAWEI ID.
INTERNAL_ERROR 1026900003 Internal error.
SERVER_ERROR 1026900004 Server error.
NETWORK_ERROR 1026900005 Network error.
PARAMETER_ERROR 1026900006 Parameter error.
UNSUPPORTED_REGION 1026900007 The service is unavailable in the country or region.
USER_CANCELED 1026900008 The user canceled the operation.
PERMISSION_CHECK_ERROR 1026900009 The app does not have the required permissions.

selectIntimates

selectIntimates(context: common.Context, request: IntimatesSelectionRequest): Promise<IntimatesSelectionResponse[]>

Launches the My circle member picker, allowing users to add and select friends and family members. This API uses a promise to return the information about the selected friends and family members. For users who have never used the My circle feature, they will be guided to add friends and family members. After users select friends and family members and tap the completion button, the information about the selected friends and family members is returned. In other scenarios, such as when a user taps the close button, a corresponding error code will be thrown.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.AuthenticationServices.HuaweiID.Intimate

Since: 26.0.0

Parameters

Parameter Type Mandatory Description
context common.Context Yes

Context.

The following contexts are supported for apps: UIAbilityContext and UIExtensionContext. Apps cannot use UIExtensionContext in non-full-screen components such as sheets, pop-ups, and sub-windows.

request IntimatesSelectionRequest Yes Request object for launching the My circle member picker. The object contains the maximum number of friends and family members that can be selected, whether to obtain only friends and family members with HUAWEI IDs, HUAWEI ID user identifier type, and HUAWEI ID user identifier (UnionID or OpenID) value.

Returns

Type Description
Promise<IntimatesSelectionResponse[]> Promise used to return an array of IntimatesSelectionResponse objects. The contained information includes the UnionIDs and OpenIDs of the selected friends and family members, as well as their anonymous accounts, avatars, and nicknames.

Error codes:

For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.

ID Error Message
801 Capability not supported because device not support intimate feature.
1026900001 The user has not logged in with HUAWEI ID.
1026900003 Internal error, possibly an IPC failure.
1026900004 Server error.
1026900005 Network error.
1026900006 Parameter check failed.
1026900007 Unsupported country/region.
1026900008 The user canceled the current operation.
1026900009 The app does not have the required permissions.

Example:

import { intimate } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

// Create request parameters.
let request: intimate.IntimatesSelectionRequest = {
  'maxSelectionCount': 1,
  'onlySelectIntimateWithHuaweiID': true,
  'idType': intimate.IdType.OPEN_ID,
  'idValue': 'xxx' // The value can be obtained through the HUAWEI ID sign-in API.
};
try {
  // Execute the request for launching the My circle member picker.
  intimate.selectIntimates(this.getUIContext().getHostContext(), request)
    .then((data: intimate.IntimatesSelectionResponse[]) => {
      // Process the obtained friend and family member information.
      hilog.info(0x000, 'test selectIntimates', 'select intimate info success, %{public}s',
        JSON.stringify(data));
    })
    .catch((err: BusinessError) => {
      hilog.error(0x000, 'test selectIntimates',
        `select intimate info failed. Code: ${err.code}, message: ${err.message}`);
    });
} catch (error) {
  hilog.error(0x000, 'test selectIntimates',
    `select intimate info failed. Code: ${error.code}, message: ${error.message}`);
}