# @ohos.account.appAccount (应用账号管理)

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

本模块提供应用账号信息的添加、删除、修改和查询基础能力。应用账号管理采用应用级账号隔离机制，每个应用的账号信息独立管理。
> 说明
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口，采用上角标单独标记接口的起始版本。

## 导入模块

> phone | 2in1 | tablet | tv | wearable

```ts
import { appAccount } from '@kit.BasicServicesKit';
```

## appAccount.createAppAccountManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAppAccountManager(): AppAccountManager

创建应用账号管理器对象。

**系统能力：** SystemCapability.Account.AppAccount

**返回值：**

|类型|说明|
|:--------------------------------------|:---------|
|[AppAccountManager](#appaccountmanager)|应用账号管理器对象。|

**示例：**

```ts
let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
```

## AppAccountManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

应用账号管理器，可用于管理应用自身的账号信息。

### createAccount^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccount(name: string, callback: AsyncCallback<void>): void

根据账号名创建应用账号。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当创建成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300004|Account already exists.|
|12300007|The number of accounts reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.createAccount('WangWu', (err: BusinessError) => {
    if (err) {
      console.error(`createAccount code: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('createAccount successful.');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`createAccount err: code is ${err.code}, message is ${err.message}`);
}
```

### createAccount^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void

根据账号名和可选项创建应用账号。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------|:-|:-----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|options|[CreateAccountOptions](#createaccountoptions9)|是|创建应用账号的选项，可提供自定义数据，但不建议包含敏感数据（如密码、Token等）。|
|callback|AsyncCallback<void>|是|回调函数。当创建成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or options.|
|12300004|Account already exists.|
|12300007|The number of accounts reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.CreateAccountOptions = {
  customData: {
    age: '10'
  }
}
try {
  appAccountManager.createAccount('LiSi', options, (err: BusinessError) => {
    if (err) {
      console.error(`createAccount failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('createAccount successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`createAccount exception: code is ${err.code}, message is ${err.message}`);
}
```

### createAccount^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccount(name: string, options?: CreateAccountOptions): Promise<void>

根据账号名和可选项创建应用账号。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:------|:---------------------------------------------|:-|:----------------------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|options|[CreateAccountOptions](#createaccountoptions9)|否|创建应用账号的选项，可提供自定义数据，但不建议包含敏感数据（如密码、Token等）。不填无影响，默认为空，表示创建的该账号无额外信息需要添加。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or options.|
|12300004|Account already exists.|
|12300007|The number of accounts reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.CreateAccountOptions = {
  customData: {
    age: '10'
  }
}
try {
  appAccountManager.createAccount('LiSi', options).then(() => {
    console.info('createAccount successfully');
  }).catch((err: BusinessError) => {
    console.error(`createAccount failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`createAccount exception: code is ${err.code}, message is ${err.message}`);
}
```

### createAccountImplicitly^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccountImplicitly(owner: string, callback: AuthCallback): void

根据指定的账号所有者，由认证器自动完成应用账号创建流程。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调对象，返回创建结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12300007|The number of accounts reaches the upper limit.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, result?: appAccount.AuthResult): void {
    console.info('resultCode: ' + code);
    console.info('result: ' + JSON.stringify(result));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    try {
      appAccountManager.createAccountImplicitly('com.example.accountjsdemo', {
        onResult: this.onResultCallback,
        onRequestRedirected: this.onRequestRedirectedCallback
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`createAccountImplicitly exception: code is ${err.code}, message is ${err.message}`);
    }
  }
  build() {}
}
```

### createAccountImplicitly^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void

根据指定的账号所有者和可选项隐式地创建应用账号。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------------------------------------------|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|options|[CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9)|是|隐式创建账号的选项。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调对象，返回创建结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner or options.|
|12300007|The number of accounts reaches the upper limit.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, result?: appAccount.AuthResult): void {
    console.info('resultCode: ' + code);
    console.info('result: ' + JSON.stringify(result));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    let options: appAccount.CreateAccountImplicitlyOptions = {
      authType: 'getSocialData',
      requiredLabels: ['student']
    };
    try {
      appAccountManager.createAccountImplicitly('com.example.accountjsdemo', options, {
        onResult: this.onResultCallback,
        onRequestRedirected: this.onRequestRedirectedCallback
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`createAccountImplicitly exception: code is ${err.code}, message is ${err.message}`);
    }
  }
  build() {}
}
```

### removeAccount^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

removeAccount(name: string, callback: AsyncCallback<void>): void

删除应用账号。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当删除成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.removeAccount('ZhaoLiu', (err: BusinessError) => {
    if (err) {
      console.error(`removeAccount failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('removeAccount successfully');
    }
 });
} catch (e) {
  const err = e as BusinessError;
  console.error(`removeAccount exception: code is ${err.code}, message is ${err.message}`);
}
```

### removeAccount^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

removeAccount(name: string): Promise<void>

删除应用账号。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.removeAccount('Lisi').then(() => {
    console.info('removeAccount successfully');
  }).catch((err: BusinessError) => {
    console.error(`removeAccount failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`removeAccount exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAppAccess^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void

设置指定应用对特定账号的数据访问权限。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-----------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|
|isAccessible|boolean|是|是否可访问。true表示允许访问，false表示禁止访问。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:---------------------------------------------------------------|
|12300001|System service exception.|
|12300002|Invalid name or bundleName.|
|12300003|Account not found.|
|12400001|Application not found. 适用版本：9 - 13|
|12400005|The size of authorization list reaches the upper limit. 适用版本：14+|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true, (err: BusinessError) => {
    if (err) {
      console.error(`setAppAccess failed: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('setAppAccess successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAppAccess^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void>

设置指定应用对特定账号的数据访问权限。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-----------|:------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|
|isAccessible|boolean|是|是否可访问。true表示允许访问，false表示禁止访问。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:---------------------------------------------------------------|
|12300001|System service exception.|
|12300002|Invalid name or bundleName.|
|12300003|Account not found.|
|12400001|Application not found. 适用版本：9 - 13|
|12400005|The size of authorization list reaches the upper limit. 适用版本：14+|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true).then(() => {
    console.info('setAppAccess successfully');
  }).catch((err: BusinessError) => {
    console.error(`setAppAccess failed: code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAppAccess^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void

检查指定应用对特定账号的数据是否可访问。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:---------------------|:-|:-----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|
|callback|AsyncCallback<boolean>|是|回调函数。返回true表示指定应用可访问特定账号的数据；返回false表示不可访问。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or bundleName.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo',
    (err: BusinessError, isAccessible: boolean) => {
      if (err) {
        console.error(`checkAppAccess failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('checkAppAccess successfully');
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAppAccess^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAppAccess(name: string, bundleName: string): Promise<boolean>

检查指定应用对特定账号的数据是否可访问。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:--------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:---------------|:----------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示指定应用可访问特定账号的数据；返回false表示不可访问。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or bundleName.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo').then((isAccessible: boolean) => {
    console.info('checkAppAccess successfully, isAccessible: ' + isAccessible);
  }).catch((err: BusinessError) => {
    console.error(`checkAppAccess failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
```

### setDataSyncEnabled^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void

开启或禁止指定应用账号的数据同步功能。使用callback异步回调。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:------------------|:-|:-----------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|isEnabled|boolean|是|是否开启数据同步。true表示开启数据同步，false表示关闭数据同步。|
|callback|AsyncCallback<void>|是|回调函数。当开启或禁止成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|201|Permission denied.|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
    appAccountManager.setDataSyncEnabled('ZhangSan', true, (err: BusinessError) => {
        console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
    });
} catch (e) {
    const err = e as BusinessError;
    console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
```

### setDataSyncEnabled^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void>

开启或禁止指定应用账号的数据同步功能。使用Promise异步回调。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:------|:-|:-----------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|isEnabled|boolean|是|是否开启数据同步。true表示开启数据同步，false表示关闭数据同步。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|201|Permission denied.|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
    appAccountManager.setDataSyncEnabled('ZhangSan', true).then(() => {
        console.info('setDataSyncEnabled Success');
    }).catch((err: BusinessError) => {
        console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
    });
} catch (e) {
    const err = e as BusinessError;
    console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
```

### checkDataSyncEnabled^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void

检查指定应用账号是否开启数据同步功能。使用callback异步回调。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<boolean>|是|回调函数。返回true表示指定应用账号已开启数据同步功能；返回false表示未开启。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|201|Permission denied.|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkDataSyncEnabled('ZhangSan', (err: BusinessError, isEnabled: boolean) => {
    if (err) {
      console.error(`checkDataSyncEnabled failed, err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
```

### checkDataSyncEnabled^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkDataSyncEnabled(name: string): Promise<boolean>

检查指定应用账号是否开启数据同步功能。使用Promise异步回调。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:---------------|:----------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示指定应用账号已开启数据同步功能；返回false表示未开启。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|201|Permission denied.|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkDataSyncEnabled('ZhangSan').then((isEnabled: boolean) => {
      console.info('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.error(`checkDataSyncEnabled failed, err: code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
```

### setCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void

设置指定应用账号的凭据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:------------------|:-|:------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|credential|string|是|凭据取值。自定义的数据，最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当凭据设置成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, credentialType or credential.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx', (err: BusinessError) => {
    if (err) {
      console.error(`setCredential failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('setCredential successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setCredential exception: code is ${err.code}, message is ${err.message}`);
}
```

### setCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setCredential(name: string, credentialType: string, credential: string): Promise<void>

设置指定应用账号的凭据。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|credential|string|是|凭据取值。自定义的数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, credentialType or credential.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx').then(() => {
    console.info('setCredential successfully');
  }).catch((err: BusinessError) => {
    console.error(`setCredential failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setCredential exception: code is ${err.code}, message is ${err.message}`);
}
```

### getCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void

获取指定应用账号的凭据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:--------------------|:-|:---------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取凭据成功时，err为null，data为指定应用账号的凭据；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or credentialType.|
|12300003|Account not found.|
|12300102|Credential not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getCredential('ZhangSan', 'PIN_SIX', (err: BusinessError, result: string) => {
    if (err) {
      console.error(`getCredential failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getCredential successfully, result: ' + result);
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getCredential err: code is ${err.code}, message is ${err.message}`);
}
```

### getCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getCredential(name: string, credentialType: string): Promise<string>

获取指定应用账号的凭据。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:--------------|:---------------------|
|Promise<string>|Promise对象，返回指定应用账号的凭据。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or credentialType.|
|12300003|Account not found.|
|12300102|Credential not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getCredential('ZhangSan', 'PIN_SIX').then((credential: string) => {
    console.info('getCredential successfully, credential: ' + credential);
  }).catch((err: BusinessError) => {
    console.error(`getCredential failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getCredential exception: code is ${err.code}, message is ${err.message}`);
}
```

### setCustomData^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void

设置指定应用账号的自定义数据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:---------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|自定义数据的键名。最大长度为1024个字符。|
|value|string|是|自定义数据的取值。不建议包含敏感数据。最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当设置自定义数据成功时，err为null，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, key or value.|
|12300003|Account not found.|
|12400003|The number of custom data reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setCustomData('ZhangSan', 'age', '12', (err: BusinessError) => {
    if (err) {
      console.error(`setCustomData failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('setCustomData successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setCustomData exception: code is ${err.code}, message is ${err.message}`);
}
```

### setCustomData^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setCustomData(name: string, key: string, value: string): Promise<void>

设置指定应用账号的自定义数据。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:---------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|自定义数据的键名。最大长度为1024个字符。|
|value|string|是|自定义数据的取值。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, key or value.|
|12300003|Account not found.|
|12400003|The number of custom data reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setCustomData('ZhangSan', 'age', '12').then(() => {
    console.info('setCustomData successfully');
  }).catch((err: BusinessError) => {
    console.error(`setCustomData failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setCustomData exception: code is ${err.code}, message is ${err.message}`);
}
```

### getCustomData^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getCustomData(name: string, key: string, callback: AsyncCallback<string>): void

根据指定键名获取特定应用账号的自定义数据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------|:-|:------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|自定义数据的键名。最大长度为1024个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取成功时，err为null，data为自定义数据的取值；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or key.|
|12300003|Account not found.|
|12400002|Custom data not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getCustomData('ZhangSan', 'age', (err: BusinessError, data: string) => {
    if (err) {
      console.error('getCustomData failed, error: ' + err);
    } else {
      console.info('getCustomData successfully, data: ' + data);
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getCustomData exception: code is ${err.code}, message is ${err.message}`);
}
```

### getCustomData^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getCustomData(name: string, key: string): Promise<string>

根据指定键名获取特定应用账号的自定义数据。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:---------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|自定义数据的键名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:--------------|:--------------------|
|Promise<string>|Promise对象，返回自定义数据的取值。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or key.|
|12300003|Account not found.|
|12400002|Custom data not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getCustomData('ZhangSan', 'age').then((data: string) => {
    console.info('getCustomData successfully, data: ' + data);
  }).catch((err: BusinessError) => {
    console.error(`getCustomData failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getCustomData exception: code is ${err.code}, message is ${err.message}`);
}
```

### getCustomDataSync^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getCustomDataSync(name: string, key: string): string

根据指定键名获取特定应用账号的自定义数据。使用同步方式返回结果。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:---------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|自定义数据的键名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:-----|:--------|
|string|自定义数据的取值。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or key.|
|12300003|Account not found.|
|12400002|Custom data not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let value = appAccountManager.getCustomDataSync('ZhangSan', 'age');
  console.info('getCustomDataSync successfully, value: ' + value);
} catch (e) {
  const err = e as BusinessError;
  console.error(`getCustomDataSync failed, code is ${err.code}, message is ${err.message}`);
}
```

### getAllAccounts^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void

获取所有可访问的应用账号信息。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:----------------------------------------------|
|callback|AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>>|是|回调函数。当查询成功时，err为null，data为获取到的应用账号信息列表；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAllAccounts((err: BusinessError, data: appAccount.AppAccountInfo[]) => {
    if (err) {
      console.error(`getAllAccounts failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getAllAccounts successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAllAccounts exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAllAccounts^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccounts(): Promise<Array<AppAccountInfo>>

获取所有可访问的应用账号信息。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**返回值：**

|类型|说明|
|:------------------------------------------------|:-------------------------|
|Promise<Array<[AppAccountInfo](#appaccountinfo)>>|Promise对象，返回全部应用已授权账号信息对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:------------------------|
|12300001|System service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAllAccounts().then((data: appAccount.AppAccountInfo[]) => {
    console.info('getAllAccounts successfully');
  }).catch((err: BusinessError) => {
    console.error(`getAllAccounts failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAllAccounts exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAccountsByOwner^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void

根据应用账号所有者获取调用方可访问的应用账号列表。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:--------------------------------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>>|是|回调函数。如果获取成功，err为null，data为获取到的应用账号列表；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:---------------------------------|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12400001|Application not found. 适用版本：9 - 13|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAccountsByOwner('com.example.accountjsdemo2',
    (err: BusinessError, data: appAccount.AppAccountInfo[]) => {
      if (err) {
        console.error(`getAccountsByOwner failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('getAccountsByOwner successfully, data:' + JSON.stringify(data));
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAccountsByOwner exception:code is ${err.code}, message is ${err.message}`);
}
```

### getAccountsByOwner^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>>

根据应用账号所有者获取调用方可访问的应用账号列表。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:----------------------|
|Promise<Array<[AppAccountInfo](#appaccountinfo)>>|Promise对象，返回获取到的应用账号列表。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:---------------------------------|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12400001|Application not found. 适用版本：9 - 13|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then((
    data: appAccount.AppAccountInfo[]) => {
    console.info('getAccountsByOwner successfully, data: ' + JSON.stringify(data));
  }).catch((err: BusinessError) => {
    console.error(`getAccountsByOwner failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAccountsByOwner exception: code is ${err.code}, message is ${err.message}`);
}
```

### on('accountChange')^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void

订阅指定应用的账号信息变更事件。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------|:-|:------------------------------------------------|
|type|'accountChange'|是|事件回调类型，支持的事件为'accountChange'，当账号所有者更新账号信息时，触发该事件。|
|owners|Array<string>|是|应用账号所有者的包名列表。|
|callback|Callback<Array<[AppAccountInfo](#appaccountinfo)>>|是|需要注册的回调函数，返回信息为发生变更的应用账号列表。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:---------------------------------|
|12300001|System service exception.|
|12300002|Invalid type or owners.|
|12400001|Application not found. 适用版本：9 - 13|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
  console.info('receive change data:' + JSON.stringify(data));
}

try {
  appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
  const err = e as BusinessError;
  console.error(`on accountChange failed, code is ${err.code}, message is ${err.message}`);
}
```

### off('accountChange')^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void

取消订阅账号信息变更事件。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------|:-|:------------------------------------------------|
|type|'accountChange'|是|事件回调类型，支持的事件为'accountChange'，当账号所有者更新账号信息时，触发该事件。|
|callback|Callback<Array<[AppAccountInfo](#appaccountinfo)>>|否|需要注销的回调函数，默认为空，表示取消该类型事件所有的回调。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid type.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
  console.info('receive change data:' + JSON.stringify(data));
}

try {
  appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
  const err = e as BusinessError;
  console.error(`on accountChange failed, code is ${err.code}, message is ${err.message}`);
}
try {
  appAccountManager.off('accountChange', changeOnCallback);
} catch (e) {
  const err = e as BusinessError;
  console.error(`off accountChange failed, code is ${err.code}, message is ${err.message}`);
}
```

### auth^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

auth(name: string, owner: string, authType: string, callback: AuthCallback): void

对应用账号进行鉴权以获取授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|callback|[AuthCallback](#authcallback9)|是|回调对象，返回鉴权结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or authType.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, authResult?: appAccount.AuthResult): void {
    console.info('resultCode: ' + code);
    console.info('authResult: ' + JSON.stringify(authResult));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    try {
      appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', {
        onResult: this.onResultCallback,
        onRequestRedirected: this.onRequestRedirectedCallback
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`auth exception: code is ${err.code}, message is ${err.message}`);
    }
  }

  build() {}
}
```

### auth^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

auth(name: string, owner: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void

对应用账号进行鉴权以获取授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|options|Record<string, Object>|是|鉴权所需的可选项。|
|callback|[AuthCallback](#authcallback9)|是|回调对象，返回鉴权结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner, authType or options.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, authResult?: appAccount.AuthResult): void {
    console.info('resultCode: ' + code);
    console.info('authResult: ' + JSON.stringify(authResult));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    let options: Record<string, Object> = {
      'password': 'xxxx',
    };
    try {
      appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, {
        onResult: this.onResultCallback,
        onRequestRedirected: this.onRequestRedirectedCallback
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`auth exception: code is ${err.code}, message is ${err.message}`);
    }
  }

  build() {}
}
```

### getAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void

获取指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------|:-|:---------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取成功时，err为null，data为授权令牌值；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or authType.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
    (err: BusinessError, token: string) => {
      if (err) {
        console.error(`getAuthToken failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('getAuthToken successfully, token: ' + token);
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthToken(name: string, owner: string, authType: string): Promise<string>

获取指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:--------------|:----------------|
|Promise<string>|Promise对象，返回授权令牌。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or authType.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token: string) => {
    console.info('getAuthToken successfully, token: ' + token);
  }).catch((err: BusinessError) => {
    console.error(`getAuthToken failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void

为指定应用账号设置特定鉴权类型的授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, authType or token.|
|12300003|Account not found.|
|12400004|The number of tokens reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
    if (err) {
      console.error(`setAuthToken failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('setAuthToken successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthToken(name: string, authType: string, token: string): Promise<void>

为指定应用账号设置特定鉴权类型的授权令牌。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, authType or token.|
|12300003|Account not found.|
|12400004|The number of tokens reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
    console.info('setAuthToken successfully');
  }).catch((err: BusinessError) => {
    console.error(`setAuthToken failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### deleteAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void

删除指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。如果授权令牌不存在，则不执行任何操作。最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当删除成功时，err为null；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner, authType or token.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
    (err: BusinessError) => {
      if (err) {
        console.error(`deleteAuthToken failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('deleteAuthToken successfully');
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`deleteAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### deleteAuthToken^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>

删除指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。如果授权令牌不存在，则不执行任何操作。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner, authType or token.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
    console.info('deleteAuthToken successfully');
  }).catch((err: BusinessError) => {
    console.error(`deleteAuthToken failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`deleteAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthTokenVisibility^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void

设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|被设置可见性的应用包名。最大长度为512个字符。|
|isVisible|boolean|是|是否可见。true表示可见，false表示不可见。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------|
|12300001|System service exception.|
|12300002|Invalid name, authType or bundleName.|
|12300003|Account not found.|
|12300107|AuthType not found.|
|12400001|Application not found. 适用版本：9 - 13|
|12400005|The size of authorization list reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
    (err: BusinessError) => {
      if (err) {
        console.error(`setAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('setAuthTokenVisibility successfully');
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthTokenVisibility^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>

设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|被设置可见性的应用包名。最大长度为512个字符。|
|isVisible|boolean|是|是否可见。true表示可见，false表示不可见。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------|
|12300001|System service exception.|
|12300002|Invalid name, authType or bundleName.|
|12300003|Account not found.|
|12300107|AuthType not found.|
|12400001|Application not found. 适用版本：9 - 13|
|12400005|The size of authorization list reaches the upper limit.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
    console.info('setAuthTokenVisibility successfully');
  }).catch((err: BusinessError) => {
    console.error(`setAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAuthTokenVisibility^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void

检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:---------------------|:-|:----------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|检查可见性的应用包名。最大长度为512个字符。|
|callback|AsyncCallback<boolean>|是|回调函数。当检查成功时，err为null，data为true表示可见，data为false表示不可见；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, authType or bundleName.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
    (err: BusinessError, isVisible: boolean) => {
      if (err) {
        console.error(`checkAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAuthTokenVisibility^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>

检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|用于检查可见性的应用包名。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:---------------|:-------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示授权令牌对指定应用的可见，返回false表示不可见。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, authType or bundleName.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
    isVisible: boolean) => {
    console.info('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
  }).catch((err: BusinessError) => {
    console.error(`checkAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAllAuthTokens^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void

获取指定账号对调用方可见的所有授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------------------------------|:-|:----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<Array<[AuthTokenInfo](#authtokeninfo9)>>|是|回调函数。当获取成功时，err为null，data为授权令牌数组；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or owner.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo',
    (err: BusinessError, tokenArr: appAccount.AuthTokenInfo[]) => {
      if (err) {
        console.error(`getAllAuthTokens failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAllAuthTokens exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAllAuthTokens^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>>

获取指定账号对调用方可见的所有授权令牌。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:-----------------------------------------------|:------------------|
|Promise<Array<[AuthTokenInfo](#authtokeninfo9)>>|Promise对象，返回授权令牌数组。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or owner.|
|12300003|Account not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then((
    tokenArr: appAccount.AuthTokenInfo[]) => {
    console.info('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
  }).catch((err: BusinessError) => {
    console.error(`getAllAuthTokens failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAllAuthTokens exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAuthList^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void

获取指定应用账号的特定鉴权类型的授权列表，即被授权的包名数组（令牌的授权列表通过[setAuthTokenVisibility](#setauthtokenvisibility9)来设置）。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------|:-|:------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|callback|AsyncCallback<Array<string>>|是|回调函数。当获取成功时，err为null，data为被授权的包名数组；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or authType.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAuthList('LiSi', 'getSocialData', (err: BusinessError, authList: string[]) => {
    if (err) {
      console.error(`getAuthList failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getAuthList successfully, authList: ' + authList);
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAuthList exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAuthList^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthList(name: string, authType: string): Promise<Array<string>>

获取指定应用账号的特定鉴权类型的授权列表，即被授权的包名数组（令牌的授权列表通过[setAuthTokenVisibility](#setauthtokenvisibility9)来设置）。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:---------------------|:--------------------|
|Promise<Array<string>>|Promise对象，返回被授权的包名数组。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or authType.|
|12300003|Account not found.|
|12300107|AuthType not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList: string[]) => {
    console.info('getAuthList successfully, authList: ' + authList);
  }).catch((err: BusinessError) => {
    console.error(`getAuthList failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`getAuthList exception: code is ${err.code}, message is ${err.message}`);
}
```

### getAuthCallback^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void

获取鉴权会话的认证器回调对象。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:--------------------------------------------|:-|:----------------------------------------------|
|sessionId|string|是|鉴权会话的标识。|
|callback|AsyncCallback<[AuthCallback](#authcallback9)>|是|回调函数。当获取成功时，err为null，data为鉴权会话的认证器回调对象；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid sessionId.|
|12300108|Session not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, param: AbilityConstant.LaunchParam) { // ability 生命周期函数
    let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
    try {
      appAccountManager.getAuthCallback(sessionId, (err: BusinessError, callback: appAccount.AuthCallback) => {
        if (err != null) {
          console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
          return;
        }
        let result: appAccount.AuthResult = {
          account: {
            name: 'Lisi',
            owner: 'com.example.accountjsdemo',
          },
          tokenInfo: {
            token: 'xxxxxx',
            authType: 'getSocialData'
          }
        };
        callback.onResult(0, result);
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`getAuthCallback exception: code is ${err.code}, message is ${err.message}`);
    }
  }
}
```

### getAuthCallback^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthCallback(sessionId: string): Promise<AuthCallback>

获取鉴权会话的认证器回调对象。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:-------|
|sessionId|string|是|鉴权会话的标识。|

**返回值：**

|类型|说明|
|:--------------------------------------|:------------------------|
|Promise<[AuthCallback](#authcallback9)>|Promise对象，返回鉴权会话的认证器回调对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid sessionId.|
|12300108|Session not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, param: AbilityConstant.LaunchParam) { // ability 生命周期函数
    let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
    try {
      appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
      let result: appAccount.AuthResult = {
        account: {
          name: 'Lisi',
          owner: 'com.example.accountjsdemo',
        },
        tokenInfo: {
          token: 'xxxxxx',
          authType: 'getSocialData'
        }
      };
      callback.onResult(0, result);
      }).catch((err: BusinessError) => {
        console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
      });
    } catch (e) {
      const err = e as BusinessError;
      console.error(`getAuthCallback exception: code is ${err.code}, message is ${err.message}`);
    }
  }
}
```

### queryAuthenticatorInfo^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void

获取指定应用的认证器信息。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:-----------------------------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)>|是|回调函数。当获取成功时，err为null，data为认证器信息对象；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12300113|Authenticator service not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo',
    (err: BusinessError, info: appAccount.AuthenticatorInfo) => {
      if (err) {
        console.error(`queryAuthenticatorInfo failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`queryAuthenticatorInfo exception: code is ${err.code}, message is ${err.message}`);
}
```

### queryAuthenticatorInfo^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>

获取指定应用的认证器信息。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:------------------------|
|Promise<[AuthenticatorInfo](#authenticatorinfo8)>|Promise对象，返回指定应用的认证器信息对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12300113|Authenticator service not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then((
    info: appAccount.AuthenticatorInfo) => {
    console.info('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
  }).catch((err: BusinessError) => {
    console.error(`queryAuthenticatorInfo failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`queryAuthenticatorInfo exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAccountLabels^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void

检查指定应用账号是否满足特定的标签集合。使用callback异步回调。该方法依赖目标应用的认证器提供标签检查的能力。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|labels|Array<string>|是|标签数组。|
|callback|AsyncCallback<boolean>|是|回调函数。当检查成功时，err为null，data为true表示满足特定的标签集合，data为false表示不满足；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or labels.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let labels = ['student'];
try {
  appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels,
    (err: BusinessError, hasAllLabels: boolean) => {
      if (err) {
        console.error(`checkAccountLabels failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels);
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAccountLabels exception: code is ${err.code}, message is ${err.message}`);
}
```

### checkAccountLabels^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean>

检查指定应用账号是否满足特定的标签集合。使用Promise异步回调。该方法依赖目标应用的认证器提供标签检查的能力。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-----|:------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|labels|Array<string>|是|标签数组。|

**返回值：**

|类型|说明|
|:---------------|:--------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示指定账号满足特定的标签集合，返回false表示不满足。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or labels.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let labels = ['student'];
try {
  appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then((
    hasAllLabels: boolean) => {
    console.info('checkAccountLabels successfully: ' + hasAllLabels);
  }).catch((err: BusinessError) => {
    console.error(`checkAccountLabels failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`checkAccountLabels exception: code is ${err.code}, message is ${err.message}`);
}
```

### deleteCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void

删除指定应用账号的特定类型的凭据信息。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当删除成功时，err为null；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or credentialType.|
|12300003|Account not found.|
|12300102|Credential not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err: BusinessError) => {
    if (err) {
      console.error(`deleteCredential failed, code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('deleteCredential successfully');
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`deleteCredential exception: code is ${err.code}, message is ${err.message}`);
}
```

### deleteCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteCredential(name: string, credentialType: string): Promise<void>

删除指定应用账号的特定类型的凭据信息。使用Promise异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or credentialType.|
|12300003|Account not found.|
|12300102|Credential not found.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => {
    console.info('deleteCredential successfully');
  }).catch((err: BusinessError) => {
    console.error(`deleteCredential failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`deleteCredential exception: code is ${err.code}, message is ${err.message}`);
}
```

### selectAccountsByOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void

根据选项选择调用方可访问的账号列表。使用callback异步回调。如果选项中包含标签约束，则该方法依赖目标应用的认证器提供标签检查的能力。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:---------------------------------------------------------|
|options|[SelectAccountsOptions](#selectaccountsoptions9)|是|选择账号的选项。|
|callback|AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>>|是|回调函数。当根据选项选择请求方可访问的账号列表时，err为null，data为可访问的账号信息对象；否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid options.|
|12300010|Account service busy.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.SelectAccountsOptions = {
  allowedOwners: ['com.example.accountjsdemo'],
  requiredLabels: ['student']
};
try {
  appAccountManager.selectAccountsByOptions(options,
    (err: BusinessError, accountArr: appAccount.AppAccountInfo[]) => {
      if (err) {
        console.error(`selectAccountsByOptions failed, code is ${err.code}, message is ${err.message}`);
      } else {
        console.info('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
      }
    });
} catch (e) {
  const err = e as BusinessError;
  console.error(`selectAccountsByOptions exception: code is ${err.code}, message is ${err.message}`);
}
```

### selectAccountsByOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>>

根据选项选择调用方可访问的账号列表。使用Promise异步回调。如果选项中包含标签约束，则该方法依赖目标应用的认证器提供标签检查的能力。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:------|:-----------------------------------------------|:-|:-------|
|options|[SelectAccountsOptions](#selectaccountsoptions9)|是|选择账号的选项。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:-----------------------|
|Promise<Array<[AppAccountInfo](#appaccountinfo)>>|Promise对象，返回调用方可访问的账号列表。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid options.|
|12300010|Account service busy.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.SelectAccountsOptions = {
  allowedOwners: ['com.example.accountjsdemo']
};
try {
  appAccountManager.selectAccountsByOptions(options).then((accountArr: appAccount.AppAccountInfo[]) => {
    console.info('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
  }).catch((err: BusinessError) => {
    console.error(`selectAccountsByOptions failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`selectAccountsByOptions exception: code is ${err.code}, message is ${err.message}`);
}
```

### verifyCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

verifyCredential(name: string, owner: string, callback: AuthCallback): void

验证指定账号的凭据有效性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|[AuthCallback](#authcallback9)|是|回调函数，返回验证结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name or owner.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', {
    onResult: (resultCode: number, result?: appAccount.AuthResult) => {
      console.info('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
      console.info('verifyCredential onResult, result: ' + JSON.stringify(result));
    },
    onRequestRedirected: (request: Want) => {
      console.info('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`verifyCredential err: code is ${err.code}, message is ${err.message}`);
}
```

### verifyCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void

验证指定账号的凭据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|options|[VerifyCredentialOptions](#verifycredentialoptions9)|是|验证凭据的选项。|
|callback|[AuthCallback](#authcallback9)|是|回调函数，返回验证结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid name, owner or options.|
|12300003|Account not found.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.VerifyCredentialOptions = {
  credentialType: 'pin',
  credential: '123456'
};
try {
  appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, {
    onResult: (resultCode: number, result?: appAccount.AuthResult) => {
      console.info('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
      console.info('verifyCredential onResult, result: ' + JSON.stringify(result));
    },
    onRequestRedirected: (request: Want) => {
      console.info('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`verifyCredential err: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthenticatorProperties^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthenticatorProperties(owner: string, callback: AuthCallback): void

设置指定应用的认证器属性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:--------------|
|owner|string|是|认证器的所有者的包名。|
|callback|[AuthCallback](#authcallback9)|是|回调函数，返回设置属性的结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', {
    onResult: (resultCode: number, result?: appAccount.AuthResult) => {
      console.info('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
      console.info('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
    },
    onRequestRedirected: (request: Want) => {
      console.info('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthenticatorProperties err: code is ${err.code}, message is ${err.message}`);
}
```

### setAuthenticatorProperties^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void

设置指定应用的认证器属性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------|:-|:---------------|
|owner|string|是|认证器的所有者的包名。|
|options|[SetPropertiesOptions](#setpropertiesoptions9)|是|设置属性的选项。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调，返回设置属性的结果。|

**错误码：**

以下错误码的详细介绍请参见[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:-------|:------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
|12300001|System service exception.|
|12300002|Invalid owner or options.|
|12300010|Account service busy.|
|12300113|Authenticator service not found.|
|12300114|Authenticator service exception.|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let options: appAccount.SetPropertiesOptions = {
  properties: { prop1: 'value1' }
};
try {
  appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, {
    onResult: (resultCode: number, result?: appAccount.AuthResult) => {
      console.info('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
      console.info('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
    },
    onRequestRedirected: (request: Want) => {
      console.info('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
    }
  });
} catch (e) {
  const err = e as BusinessError;
  console.error(`setAuthenticatorProperties err: code is ${err.code}, message is ${err.message}`);
}
```

### addAccount^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addAccount(name: string, callback: AsyncCallback<void>): void

根据账号名添加应用账号。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[createAccount](#createaccount9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当创建成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.addAccount('WangWu', (err: BusinessError) => {
  console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
```

### addAccount^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void

根据账号名和额外信息添加应用账号。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[createAccount](#createaccount9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:------------------|:-|:-------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|extraInfo|string|是|额外信息(能转换string类型的其它信息)，额外信息不能是应用账号的敏感信息（如应用账号密码、token等）。|
|callback|AsyncCallback<void>|是|回调函数。当创建成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.addAccount('LiSi', 'token101', (err: BusinessError) => {
  console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
```

### addAccount^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addAccount(name: string, extraInfo?: string): Promise<void>

根据账号名和额外信息添加应用账号。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[createAccount](#createaccount9-2)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:------------------------------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|extraInfo|string|否|额外信息(能转换string类型的其它信息)，额外信息不能是应用账号的敏感信息（如应用账号密码、token等），默认为空，表示创建的该账号无额外信息需要添加。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.addAccount('LiSi', 'token101').then(()=> {
  console.info('addAccount Success');
}).catch((err: BusinessError) => {
  console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
```

### addAccountImplicitly^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addAccountImplicitly(owner: string, authType: string, options: { [key: string]: any }, callback: AuthenticatorCallback): void

根据指定的账号所有者隐式地添加应用账号。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[createAccountImplicitly](#createaccountimplicitly9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------------------------------------------|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|options|{[key: string]: any}|是|鉴权所需要的可选项。可选项可根据自己需要设置。|
|callback|[AuthenticatorCallback](#authenticatorcallbackdeprecated)|是|认证器回调对象，返回添加结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, result: Record<string, Object>): void {
    console.info('resultCode: ' + code);
    console.info('result: ' + JSON.stringify(result));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    appAccountManager.addAccountImplicitly('com.example.accountjsdemo', 'getSocialData', {}, {
      onResult: this.onResultCallback,
      onRequestRedirected: this.onRequestRedirectedCallback
    });
  }

  build() {}
}
```

### deleteAccount^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteAccount(name: string, callback: AsyncCallback<void>): void

删除应用账号。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[removeAccount](#removeaccount9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当删除成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.deleteAccount('ZhaoLiu', (err: BusinessError) => {
  console.error(`deleteAccount err: code is ${err.code}, message is ${err.message}`);
});
```

### deleteAccount^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteAccount(name: string): Promise<void>

删除应用账号。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[removeAccount](#removeaccount9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.deleteAccount('ZhaoLiu').then(() => {
  console.info('deleteAccount Success');
}).catch((err: BusinessError) => {
  console.error(`deleteAccount err: code is ${err.code}, message is ${err.message}`);
});
```

### disableAppAccess^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void

禁止指定第三方应用账号对指定包名称的第三方应用进行访问。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setAppAccess](#setappaccess9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------------------|:-|:-------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当禁止指定第三方应用账号对指定包名称的第三方应用进行访问设置成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
  console.error(`disableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
```

### disableAppAccess^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

disableAppAccess(name: string, bundleName: string): Promise<void>

禁止指定第三方应用账号名称对指定包名称的第三方应用进行访问。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setAppAccess](#setappaccess9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:----------------------------|
|name|string|是|要禁用访问的第三方应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
  console.info('disableAppAccess Success');
}).catch((err: BusinessError) => {
  console.error(`disableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
```

### enableAppAccess^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void

允许指定第三方应用账号名称对指定包名称的第三方应用进行访问。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setAppAccess](#setappaccess9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------------------|:-|:---------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|
|callback|AsyncCallback<void>|是|回调函数。当允许指定第三方应用账号名称对指定包名称的第三方应用进行访问设置成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
  if (err) {
    console.error(`enableAppAccess err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('enableAppAccess successful.');
  }
});
```

### enableAppAccess^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

enableAppAccess(name: string, bundleName: string): Promise<void>

允许指定第三方应用账号的名称对指定包名称的第三方应用进行访问。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setAppAccess](#setappaccess9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:--------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|bundleName|string|是|第三方应用的包名。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
  console.info('enableAppAccess Success');
}).catch((err: BusinessError) => {
  console.error(`enableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
```

### checkAppAccountSyncEnable^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void

检查指定应用账号是否开启数据同步功能。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[checkDataSyncEnabled](#checkdatasyncenabled9)替代。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<boolean>|是|回调函数。返回true表示指定应用账号已开启数据同步功能；返回false表示未开启。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err: BusinessError, result: boolean) => {
  if (err) {
    console.error(`checkAppAccountSyncEnable code: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('checkAppAccountSyncEnable result: ' + result);
  }
});
```

### checkAppAccountSyncEnable^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAppAccountSyncEnable(name: string): Promise<boolean>

检查指定应用账号是否开启数据同步功能。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[checkDataSyncEnabled](#checkdatasyncenabled9-1)替代。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:---------------|:----------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示指定应用账号已开启数据同步功能；返回false表示未开启。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data: boolean) => {
  console.info('checkAppAccountSyncEnable, result: ' + data);
}).catch((err: BusinessError) => {
  console.error(`checkAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
});
```

### setAccountCredential^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void

设置指定应用账号的凭据。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCredential](#setcredential9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:------------------|:-|:-------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|credential|string|是|凭据取值。自定义的数据，最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当设置指定应用账号的凭据成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err: BusinessError) => {
  if (err) {
    console.error(`setAccountCredential err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('setAccountCredential successful.');
  }
});
```

### setAccountCredential^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>

设置指定应用账号的凭据。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCredential](#setcredential9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|credential|string|是|凭据取值。自定义的数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => {
  console.info('setAccountCredential Success');
}).catch((err: BusinessError) => {
  console.error(`setAccountCredential err: code is ${err.code}, message is ${err.message}`);
});
```

### setAccountExtraInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void

设置指定应用账号的额外信息。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCustomData](#setcustomdata9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:------------------|:-|:-------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|extraInfo|string|是|额外信息(能转换string类型的其它信息)，额外信息不能是应用账号的敏感信息（如应用账号密码、token等）。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err: BusinessError) => {
  if (err) {
    console.error(`setAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('setAccountExtraInfo successful.');
  }
});
```

### setAccountExtraInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAccountExtraInfo(name: string, extraInfo: string): Promise<void>

设置指定应用账号的额外信息。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCustomData](#setcustomdata9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:-------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|extraInfo|string|是|额外信息(能转换string类型的其它信息)，额外信息不能是应用账号的敏感信息（如应用账号密码、token等）。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => {
  console.info('setAccountExtraInfo Success');
}).catch((err: BusinessError) => {
  console.error(`setAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
});
```

### setAppAccountSyncEnable^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void

开启或禁止指定应用账号的数据同步功能。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setDataSyncEnabled](#setdatasyncenabled9)替代。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:-----------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|isEnable|boolean|是|是否开启数据同步。true表示开启数据同步，false表示关闭数据同步。|
|callback|AsyncCallback<void>|是|回调函数。当开启或禁止成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err: BusinessError) => {
  if (err) {
    console.error(`setAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('setAppAccountSyncEnable successful.');
  }
});
```

### setAppAccountSyncEnable^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>

开启或禁止指定应用账号的数据同步功能。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setDataSyncEnabled](#setdatasyncenabled9-1)替代。

**需要权限：** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------|:-|:-----------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|isEnable|boolean|是|是否开启数据同步。true表示开启数据同步，false表示关闭数据同步。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAppAccountSyncEnable('ZhangSan', true).then(() => {
  console.info('setAppAccountSyncEnable Success');
}).catch((err: BusinessError) => {
  console.error(`setAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
});
```

### setAssociatedData^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void

设置指定应用账号的关联数据。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCustomData](#setcustomdata9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:---------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|关联数据的键名。|
|value|string|是|关联数据的取值。|
|callback|AsyncCallback<void>|是|回调函数。当设置与此应用账号关联的数据成功时，err为null，否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err: BusinessError) => {
  if (err) {
    console.error(`setAssociatedData err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('setAssociatedData successful.');
  }
});
```

### setAssociatedData^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setAssociatedData(name: string, key: string, value: string): Promise<void>

设置指定应用账号的关联数据。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[setCustomData](#setcustomdata9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|关联数据的键名。|
|value|string|是|关联数据的取值。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => {
  console.info('setAssociatedData Success');
}).catch((err: BusinessError) => {
  console.error(`setAssociatedData err: code is ${err.code}, message is ${err.message}`);
});
```

### getAllAccessibleAccounts^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void

获取所有可访问的应用账号信息。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getAllAccounts](#getallaccounts9)替代。

**需要权限：** ohos.permission.GET_ALL_APP_ACCOUNTS，该权限仅系统应用可申请。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:----------------------------------------------|
|callback|AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>>|是|回调函数。当查询成功时，err为null，data为获取到的应用账号信息列表；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAllAccessibleAccounts((err: BusinessError, data: appAccount.AppAccountInfo[])=>{
  if (err) {
    console.error(`getAllAccessibleAccounts err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getAllAccessibleAccounts data: ' + JSON.stringify(data));
  }
});
```

### getAllAccessibleAccounts^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>

获取所有可访问的应用账号信息。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getAllAccounts](#getallaccounts9-1)替代。

**需要权限：** ohos.permission.GET_ALL_APP_ACCOUNTS，该权限仅系统应用可申请。

**系统能力：** SystemCapability.Account.AppAccount

**返回值：**

|类型|说明|
|:------------------------------------------------|:-------------------------|
|Promise<Array<[AppAccountInfo](#appaccountinfo)>>|Promise对象，返回全部应用已授权账号信息对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAllAccessibleAccounts().then((data: appAccount.AppAccountInfo[]) => {
  console.info('getAllAccessibleAccounts: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getAllAccessibleAccounts err: code is ${err.code}, message is ${err.message}`);
});
```

### getAllAccounts^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void

根据应用账号所有者获取调用方可访问的应用账号列表。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getAccountsByOwner](#getaccountsbyowner9)替代。

**需要权限：** ohos.permission.GET_ALL_APP_ACCOUNTS，该权限仅系统应用可申请。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:------------------------------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>>|是|回调函数。当获取成功时，err为null，data为应用账号信息列表；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle, (err: BusinessError, data: appAccount.AppAccountInfo[])=>{
  if (err) {
    console.error(`getAllAccounts err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getAllAccounts data:' + JSON.stringify(data));
  }
});
```

### getAllAccounts^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>

根据应用账号所有者获取调用方可访问的应用账号列表。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getAccountsByOwner](#getaccountsbyowner9-1)替代。

**需要权限：** ohos.permission.GET_ALL_APP_ACCOUNTS，该权限仅系统应用可申请。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:------------------------|
|Promise<Array<[AppAccountInfo](#appaccountinfo)>>|Promise对象，返回指定应用全部账号信息对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle).then((data: appAccount.AppAccountInfo[]) => {
  console.info('getAllAccounts: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getAllAccounts err: code is ${err.code}, message is ${err.message}`);
});
```

### getAccountCredential^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void

获取指定应用账号的凭据。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCredential](#getcredential9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:--------------------|:-|:---------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取凭据成功时，err为null，data为指定应用账号的凭据；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err: BusinessError, result: string) => {
  if (err) {
    console.error(`getAccountCredential err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getAccountCredential result: ' + result);
  }
});
```

### getAccountCredential^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountCredential(name: string, credentialType: string): Promise<string>

获取指定应用账号的凭据。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCredential](#getcredential9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|credentialType|string|是|凭据类型。自定义的类型，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:--------------|:---------------------|
|Promise<string>|Promise对象，返回指定应用账号的凭据。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data: string) => {
  console.info('getAccountCredential, result: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getAccountCredential err: code is ${err.code}, message is ${err.message}`);
});
```

### getAccountExtraInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void

获取指定应用账号的额外信息（能转换成string类型的其它信息）。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCustomData](#getcustomdata9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------|:-|:---------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取此应用账号的额外信息成功时，err为null，data返回此应用账号的额外信息对象；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAccountExtraInfo('ZhangSan', (err: BusinessError, result: string) => {
  if (err) {
    console.error(`getAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getAccountExtraInfo result: ' + result);
  }
});
```

### getAccountExtraInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAccountExtraInfo(name: string): Promise<string>

获取指定应用账号的额外信息（能转换成string类型的其它信息）。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCustomData](#getcustomdata9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:--------------|:-----------------------|
|Promise<string>|Promise对象，返回指定应用账号的额外信息。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAccountExtraInfo('ZhangSan').then((data: string) => {
  console.info('getAccountExtraInfo, result: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
});
```

### getAssociatedData^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void

根据指定键名获取特定应用账号的关联数据。使用callback异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCustomData](#getcustomdata9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------|:-|:-----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|关联数据的键名。|
|callback|AsyncCallback<string>|是|回调函数。当获取成功时，err为null，data为关联数据的取值；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAssociatedData('ZhangSan', 'k001', (err: BusinessError, result: string) => {
  if (err) {
    console.error(`getAssociatedData err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getAssociatedData result: ' + result);
  }
});
```

### getAssociatedData^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAssociatedData(name: string, key: string): Promise<string>

获取指定应用账号的关联数据。使用Promise异步回调。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[getCustomData](#getcustomdata9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|key|string|是|关联数据的键名。|

**返回值：**

|类型|说明|
|:--------------|:-------------------|
|Promise<string>|Promise对象，返回关联数据的取值。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data: string) => {
  console.info('getAssociatedData: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getAssociatedData err: code is ${err.code}, message is ${err.message}`);
});
```

### on('change')^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void

订阅指定应用的账号信息变更事件。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[on('accountChange')](#onaccountchange9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------|:-|:-----------------------------------------|
|type|'change'|是|事件回调类型，支持的事件为'change'，当账号所有者更新账号信息时，触发该事件。|
|owners|Array<string>|是|应用账号所有者的包名列表。|
|callback|Callback<Array<[AppAccountInfo](#appaccountinfo)>>|是|需要注册的回调函数，返回信息发生变更的应用账号列表。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
  console.info('receive change data:' + JSON.stringify(data));
}

try {
  appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
  const err = e as BusinessError;
  console.error(`on accountOnOffDemo code is ${err.code}, message is ${err.message}`);
}
```

### off('change')^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void

取消订阅账号信息变更事件。
> 说明
>
> 从API version 7开始支持，从API version 9开始废弃，建议使用[off('accountChange')](#offaccountchange9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------|:-|:-----------------------------------------|
|type|'change'|是|事件回调类型，支持的事件为'change'，当账号所有者更新账号信息时，触发该事件。|
|callback|Callback<Array<[AppAccountInfo](#appaccountinfo)>>|否|需要注销的回调函数，默认为空，表示取消该类型事件的所有回调。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
  console.info('receive change data: ' + JSON.stringify(data));
  appAccountManager.off('change', () => {
    console.info('off finish');
  })
}

try {
  appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
  const err = e as BusinessError;
  console.error(`on accountOnOffDemo err: code is ${err.code}, message is ${err.message}`);
}
```

### authenticate^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

authenticate(name: string, owner: string, authType: string, options: { [key: string]: any }, callback: AuthenticatorCallback): void

对应用账号进行鉴权以获取授权令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[auth](#auth9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------------------------------------------|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|options|{[key: string]: any}|是|鉴权所需的可选项。|
|callback|[AuthenticatorCallback](#authenticatorcallbackdeprecated)|是|回调对象，返回鉴权结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext

  onResultCallback(code: number, result: Record<string, Object>): void {
    console.info('resultCode: ' + code);
    console.info('result: ' + JSON.stringify(result));
  }

  onRequestRedirectedCallback(request: Want): void {
    let wantInfo: Want = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.info('startAbility successfully');
    }).catch((err: BusinessError) => {
      console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
    })
  }

  aboutToAppear(): void {
    appAccountManager.authenticate('LiSi', 'com.example.accountjsdemo', 'getSocialData', {}, {
      onResult: this.onResultCallback,
      onRequestRedirected: this.onRequestRedirectedCallback
    });
  }

  build() {}
}
```

### getOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void

获取指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthToken](#getauthtoken9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:--------------------|:-|:---------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|callback|AsyncCallback<string>|是|回调函数。当获取成功时，err为null，data为授权令牌值；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
  (err: BusinessError, data: string) => {
    if (err) {
      console.error(`getOAuthToken err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getOAuthToken token: ' + data);
    }
  });
```

### getOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOAuthToken(name: string, owner: string, authType: string): Promise<string>

获取指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthToken](#getauthtoken9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:--------------|:----------------|
|Promise<string>|Promise对象，返回授权令牌。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data: string) => {
  console.info('getOAuthToken token: ' + data);
}).catch((err: BusinessError) => {
  console.error(`getOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
```

### setOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void

为指定应用账号设置特定鉴权类型的授权令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[setAuthToken](#setauthtoken9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
  if (err) {
    console.error(`setOAuthToken err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('setOAuthToken successful.');
  }
});
```

### setOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setOAuthToken(name: string, authType: string, token: string): Promise<void>

为指定应用账号设置特定鉴权类型的授权令牌。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[setAuthToken](#setauthtoken9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
  console.info('setOAuthToken successfully');
}).catch((err: BusinessError) => {
  console.error(`setOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
```

### deleteOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void

删除指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[deleteAuthToken](#deleteauthtoken9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|
|callback|AsyncCallback<void>|是|回调函数。当删除成功时，err为null；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
  (err: BusinessError) => {
    if (err) {
      console.error(`deleteOAuthToken err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('deleteOAuthToken successful.');
    }
  });
```

### deleteOAuthToken^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>

删除指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[deleteAuthToken](#deleteauthtoken9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|token|string|是|授权令牌。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
  console.info('deleteOAuthToken successfully');
}).catch((err: BusinessError) => {
  console.error(`deleteOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
```

### setOAuthTokenVisibility^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void

设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[setAuthTokenVisibility](#setauthtokenvisibility9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|被设置可见性的应用包名。最大长度为512个字符。|
|isVisible|boolean|是|是否可见。true表示可见，false表示不可见。|
|callback|AsyncCallback<void>|是|回调函数。当设置成功时，err为null；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
  (err: BusinessError) => {
    if (err) {
      console.error(`setOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('setOAuthTokenVisibility successful.');
    }
  });
```

### setOAuthTokenVisibility^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>

设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[setAuthTokenVisibility](#setauthtokenvisibility9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:------|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|被设置可见性的应用包名。最大长度为512个字符。|
|isVisible|boolean|是|是否可见。true表示可见，false表示不可见。|

**返回值：**

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
  console.info('setOAuthTokenVisibility successfully');
}).catch((err: BusinessError) => {
  console.error(`setOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
});
```

### checkOAuthTokenVisibility^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void

检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[checkAuthTokenVisibility](#checkauthtokenvisibility9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:---------------------|:-|:----------------------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|检查可见性的应用包名。最大长度为512个字符。|
|callback|AsyncCallback<boolean>|是|回调函数。当检查成功时，err为null，data为true表示可见，data为false表示不可见；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
  (err: BusinessError, data: boolean) => {
    if (err) {
      console.error(`checkOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('checkOAuthTokenVisibility isVisible: ' + data);
    }
  });
```

### checkOAuthTokenVisibility^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>

检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[checkAuthTokenVisibility](#checkauthtokenvisibility9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|bundleName|string|是|用于检查可见性的应用包名。最大长度为512个字符。|

**返回值：**

|类型|说明|
|:---------------|:-----------------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示指定鉴权类型的OAuth令牌对特定应用的可见，返回false表示不可见。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
  data: boolean) => {
  console.info('checkOAuthTokenVisibility isVisible: ' + data);
}).catch((err: BusinessError) => {
  console.error(`checkOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
});
```

### getAllOAuthTokens^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void

获取指定账号对调用方可见的所有授权令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAllAuthTokens](#getallauthtokens9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------|:-|:----------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<Array<[OAuthTokenInfo](#oauthtokeninfodeprecated)>>|是|回调函数。当获取成功时，err为null，data为授权令牌数组；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo',
  (err: BusinessError, data: appAccount.OAuthTokenInfo[]) => {
    if (err) {
      console.error(`getAllOAuthTokens err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getAllOAuthTokens data: ' + JSON.stringify(data));
    }
  });
```

### getAllOAuthTokens^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>>

获取指定账号对调用方可见的所有授权令牌。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAllAuthTokens](#getallauthtokens9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:-----------------------------------------------------------|:------------------|
|Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>>|Promise对象，返回授权令牌数组。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then((
  data: appAccount.OAuthTokenInfo[]) => {
  console.info('getAllOAuthTokens data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`getAllOAuthTokens err: code is ${err.code}, message is ${err.message}`);
});
```

### getOAuthList^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void

获取指定应用账号的特定鉴权类型的授权列表，即被授权的包名数组（令牌的授权列表通过[setOAuthTokenVisibility](#setoauthtokenvisibilitydeprecated)来设置）。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthList](#getauthlist9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------|:-|:------------------------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|
|callback|AsyncCallback<Array<string>>|是|回调函数。当获取成功时，err为null，data为被授权的包名数组；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getOAuthList('LiSi', 'getSocialData', (err: BusinessError, data: string[]) => {
  if (err) {
    console.error(`getOAuthList err: code is ${err.code}, message is ${err.message}`);
  } else {
    console.info('getOAuthList data: ' + JSON.stringify(data));
  }
});
```

### getOAuthList^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOAuthList(name: string, authType: string): Promise<Array<string>>

获取指定应用账号的特定鉴权类型的授权列表，即被授权的包名数组（令牌的授权列表通过[setOAuthTokenVisibility](#setoauthtokenvisibilitydeprecated)来设置）。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthList](#getauthlist9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-----------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|鉴权类型。自定义数据，最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:---------------------|:--------------------|
|Promise<Array<string>>|Promise对象，返回被授权的包名数组。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data: string[]) => {
  console.info('getOAuthList data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`getOAuthList err: code is ${err.code}, message is ${err.message}`);
});
```

### getAuthenticatorCallback^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void

获取鉴权会话的认证器回调。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthCallback](#getauthcallback9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----------------------------------------------------------------------|:-|:-----------------------------------------------------|
|sessionId|string|是|鉴权会话的标识。|
|callback|AsyncCallback<[AuthenticatorCallback](#authenticatorcallbackdeprecated)>|是|回调函数。当获取鉴权会话的认证器回调函数成功时，err为null，data为认证器回调函数；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, param: AbilityConstant.LaunchParam) { // ability 生命周期函数
    let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
    appAccountManager.getAuthenticatorCallback(sessionId,
        (err: BusinessError, callback: appAccount.AuthenticatorCallback) => {
        if (err.code != appAccount.ResultCode.SUCCESS) {
            console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
            return;
        }
        callback.onResult(appAccount.ResultCode.SUCCESS, {
          name: 'LiSi',
          owner: 'com.example.accountjsdemo',
          authType: 'getSocialData',
          token: 'xxxxxx'
        });
      });
  }
}
```

### getAuthenticatorCallback^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback>

获取鉴权会话的认证器回调。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getAuthCallback](#getauthcallback9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:-------|
|sessionId|string|是|鉴权会话的标识。|

**返回值：**

|类型|说明|
|:-----------------------------------------------------------------|:------------------------|
|Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)>|Promise对象，返回鉴权会话的认证器回调对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, param: AbilityConstant.LaunchParam) { // ability 生命周期函数
    let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
    appAccountManager.getAuthenticatorCallback(sessionId).then((
      callback: appAccount.AuthenticatorCallback) => {
      callback.onResult(appAccount.ResultCode.SUCCESS, {
        name: 'LiSi',
        owner: 'com.example.accountjsdemo',
        authType: 'getSocialData',
        token: 'xxxxxx'
      });
    }).catch((err: BusinessError) => {
      console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
    });
  }
}
```

### getAuthenticatorInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void

获取指定应用的认证器信息。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[queryAuthenticatorInfo](#queryauthenticatorinfo9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------|:-|:-----------------------------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|
|callback|AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)>|是|回调函数。当获取成功时，err为null，data为认证器信息对象；否则为错误对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo',
  (err: BusinessError, data: appAccount.AuthenticatorInfo) => {
    if (err) {
      console.error(`getAuthenticatorInfo err: code is ${err.code}, message is ${err.message}`);
    } else {
      console.info('getAuthenticatorInfo data: ' + JSON.stringify(data));
    }
  });
```

### getAuthenticatorInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>

获取指定应用的认证器信息。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[queryAuthenticatorInfo](#queryauthenticatorinfo9-1)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----------------------|
|owner|string|是|应用账号所有者的包名。最大长度为1024个字符。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:------------------------|
|Promise<[AuthenticatorInfo](#authenticatorinfo8)>|Promise对象，返回指定应用的认证器信息对象。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then((
  data: appAccount.AuthenticatorInfo) => {
  console.info('getAuthenticatorInfo: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`getAuthenticatorInfo err: code is ${err.code}, message is ${err.message}`);
});
```

## AppAccountInfo

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示应用账号信息。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:----|:-----|:-|:-|:----------|
|owner|string|否|否|应用账号所有者的包名。|
|name|string|否|否|应用账号的名称。|

## AuthTokenInfo^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示Auth令牌信息。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:-------|:--------------------------------|:-|:-|:--------------|
|authType|string|否|否|令牌的鉴权类型。|
|token|string|否|否|令牌的取值。|
|account|[AppAccountInfo](#appaccountinfo)|否|是|令牌所属的账号信息，默认为空。|

## OAuthTokenInfo^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示OAuth令牌信息。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[AuthTokenInfo](#authtokeninfo9)替代。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:-------|:-----|:-|:-|:-------|
|authType|string|否|否|令牌的鉴权类型。|
|token|string|否|否|令牌的取值。|

## AuthenticatorInfo^8+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示OAuth认证器信息。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:------|:-----|:-|:-|:----------|
|owner|string|否|否|认证器的所有者的包名。|
|iconId|number|否|否|认证器的图标标识。|
|labelId|number|否|否|认证器的标签标识。|

## AuthResult^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示认证结果信息。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:--------|:--------------------------------|:-|:-|:--------------|
|account|[AppAccountInfo](#appaccountinfo)|否|是|令牌所属的账号信息，默认为空。|
|tokenInfo|[AuthTokenInfo](#authtokeninfo9)|否|是|令牌信息，默认为空。|

## CreateAccountOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示创建账号的选项。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:---------|:---------------------|:-|:-|:--------------------|
|customData|Record<string, string>|否|是|自定义数据，默认为空。不建议包含敏感数据。|

## CreateAccountImplicitlyOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示隐式创建账号的选项。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:-------------|:---------------------|:-|:-|:------------|
|requiredLabels|Array<string>|否|是|所需的标签，默认为空。|
|authType|string|否|是|鉴权类型，默认为空。|
|parameters|Record<string, Object>|否|是|自定义参数对象，默认为空。|

## SelectAccountsOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示用于选择账号的选项。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:--------------|:---------------------------------------|:-|:-|:---------------|
|allowedAccounts|Array<[AppAccountInfo](#appaccountinfo)>|否|是|允许的账号数组，默认为空。|
|allowedOwners|Array<string>|否|是|允许的账号所有者数组，默认为空。|
|requiredLabels|Array<string>|否|是|认证器的标签标识，默认为空。|

## VerifyCredentialOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示用于验证凭据的选项。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:-------------|:---------------------|:-|:-|:------------|
|credentialType|string|否|是|凭据类型，默认为空。|
|credential|string|否|是|凭据取值，默认为空。|
|parameters|Record<string, Object>|否|是|自定义参数对象，默认为空。|

## SetPropertiesOptions^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示用于设置属性的选项。

**系统能力：** SystemCapability.Account.AppAccount

|名称|类型|只读|可选|说明|
|:---------|:---------------------|:-|:-|:------------|
|properties|Record<string, Object>|否|是|属性对象，默认为空。|
|parameters|Record<string, Object>|否|是|自定义参数对象，默认为空。|

## Constants^8+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示常量的枚举。

**系统能力：** SystemCapability.Account.AppAccount

|名称|值|说明|
|:------------------------------------------|:---------------------------|:------------------------------------------------------------------------------------------------|
|ACTION_ADD_ACCOUNT_IMPLICITLY^(deprecated)^|'addAccountImplicitly'|表示操作，隐式添加账号。 **说明：**从API version 8开始支持，从API version 9开始废弃，建议使用ACTION_CREATE_ACCOUNT_IMPLICITLY替代。|
|ACTION_AUTHENTICATE^(deprecated)^|'authenticate'|表示操作，鉴权。 **说明：**从API version 8开始支持，从API version 9开始废弃，建议使用ACTION_AUTH替代。|
|ACTION_CREATE_ACCOUNT_IMPLICITLY^9+^|'createAccountImplicitly'|表示操作，隐式创建账号。|
|ACTION_AUTH^9+^|'auth'|表示操作，鉴权。|
|ACTION_VERIFY_CREDENTIAL^9+^|'verifyCredential'|表示操作，验证凭据。|
|ACTION_SET_AUTHENTICATOR_PROPERTIES^9+^|'setAuthenticatorProperties'|表示操作，设置认证器属性。|
|KEY_NAME|'name'|表示键名，应用账号的名称。|
|KEY_OWNER|'owner'|表示键名，应用账号所有者的包名。|
|KEY_TOKEN|'token'|表示键名，令牌。|
|KEY_ACTION|'action'|表示键名，操作。|
|KEY_AUTH_TYPE|'authType'|表示键名，鉴权类型。|
|KEY_SESSION_ID|'sessionId'|表示键名，会话标识。|
|KEY_CALLER_PID|'callerPid'|表示键名，调用方PID。|
|KEY_CALLER_UID|'callerUid'|表示键名，调用方UID。|
|KEY_CALLER_BUNDLE_NAME|'callerBundleName'|表示键名，调用方包名。|
|KEY_REQUIRED_LABELS^9+^|'requiredLabels'|表示键名，必需的标签。|
|KEY_BOOLEAN_RESULT^9+^|'booleanResult'|表示键名，布尔返回值。|

## ResultCode^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示返回码的枚举。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，相关信息建议查看[账号管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-account)替代。

**系统能力：** SystemCapability.Account.AppAccount

|名称|值|说明|
|:----------------------------------|:----|:-----------|
|SUCCESS|0|表示操作成功。|
|ERROR_ACCOUNT_NOT_EXIST|10001|表示应用账号不存在。|
|ERROR_APP_ACCOUNT_SERVICE_EXCEPTION|10002|表示应用账号服务异常。|
|ERROR_INVALID_PASSWORD|10003|表示密码无效。|
|ERROR_INVALID_REQUEST|10004|表示请求无效。|
|ERROR_INVALID_RESPONSE|10005|表示响应无效。|
|ERROR_NETWORK_EXCEPTION|10006|表示网络异常。|
|ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST|10007|表示认证器不存在。|
|ERROR_OAUTH_CANCELED|10008|表示鉴权取消。|
|ERROR_OAUTH_LIST_TOO_LARGE|10009|表示开放授权列表过大。|
|ERROR_OAUTH_SERVICE_BUSY|10010|表示开放授权服务忙碌。|
|ERROR_OAUTH_SERVICE_EXCEPTION|10011|表示开放授权服务异常。|
|ERROR_OAUTH_SESSION_NOT_EXIST|10012|表示鉴权会话不存在。|
|ERROR_OAUTH_TIMEOUT|10013|表示鉴权超时。|
|ERROR_OAUTH_TOKEN_NOT_EXIST|10014|表示开放授权令牌不存在。|
|ERROR_OAUTH_TOKEN_TOO_MANY|10015|表示开放授权令牌过多。|
|ERROR_OAUTH_UNSUPPORT_ACTION|10016|表示不支持的鉴权操作。|
|ERROR_OAUTH_UNSUPPORT_AUTH_TYPE|10017|表示不支持的鉴权类型。|
|ERROR_PERMISSION_DENIED|10018|表示权限不足。|

## AuthCallback^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

认证器回调类。

### onResult^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

onResult: (code: number, result?: AuthResult) => void

通知请求结果。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-----|:-------------------------|:-|:---------------------|
|code|number|是|鉴权结果码。|
|result|[AuthResult](#authresult9)|否|鉴权结果，默认为空，表示不接收认证结果信息。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
  let result: appAccount.AuthResult = {
    account: {
      name: 'Lisi',
      owner: 'com.example.accountjsdemo',
    },
    tokenInfo: {
      token: 'xxxxxx',
      authType: 'getSocialData'
    }
  };
  callback.onResult(0, result);
}).catch((err: BusinessError) => {
  console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
});
```

### onRequestRedirected^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

onRequestRedirected: (request: Want) => void

通知请求被跳转。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:------|:-------------------------------------------------------------------------------------------------|:-|:---------|
|request|[Want](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-want)|是|用于跳转的请求信息。|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';

class MyAuthenticator extends appAccount.Authenticator {
  createAccountImplicitly(
    options: appAccount.CreateAccountImplicitlyOptions, callback: appAccount.AuthCallback) {
    let want: Want = {
      bundleName: 'com.example.accountjsdemo',
      abilityName: 'com.example.accountjsdemo.LoginAbility',
    };
    callback.onRequestRedirected(want);
  }

  auth(name: string, authType: string,
    options: Record<string, Object>, callback: appAccount.AuthCallback) {
    let result: appAccount.AuthResult = {
      account: {
        name: 'Lisi',
        owner: 'com.example.accountjsdemo',
      },
      tokenInfo: {
        token: 'xxxxxx',
        authType: 'getSocialData'
      }
    };
    callback.onResult(0, result);
  }
}
```

### onRequestContinued^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

onRequestContinued?: () => void

通知请求被继续处理。

**系统能力：** SystemCapability.Account.AppAccount

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
  if (callback.onRequestContinued != undefined) {
    callback.onRequestContinued();
  }
}).catch((err: BusinessError) => {
  console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
});
```

## AuthenticatorCallback^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

OAuth认证器回调接口。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[AuthCallback](#authcallback9)替代。

### onResult^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

onResult: (code: number, result: { [key: string]: any }) => void

通知请求结果。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[onResult](#onresult9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-----|:-------------------|:-|:-----|
|code|number|是|鉴权结果码。|
|result|{[key: string]: any}|是|鉴权结果。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthenticatorCallback(sessionId).then((callback: appAccount.AuthenticatorCallback) => {
  callback.onResult(appAccount.ResultCode.SUCCESS, {
    name: 'LiSi',
    owner: 'com.example.accountjsdemo',
    authType: 'getSocialData',
    token: 'xxxxxx'
  });
}).catch((err: BusinessError) => {
  console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
});
```

### onRequestRedirected^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

onRequestRedirected: (request: Want) => void

通知请求被跳转。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[onRequestRedirected](#onrequestredirected9)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:------|:-------------------------------------------------------------------------------------------------|:-|:---------|
|request|[Want](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-want)|是|用于跳转的请求信息。|

**示例：**

```ts
import { Want } from '@kit.AbilityKit';

class MyAuthenticator extends appAccount.Authenticator {
  addAccountImplicitly(authType: string, callerBundleName: string,
    options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) {
    let want: Want = {
      bundleName: 'com.example.accountjsdemo',
      abilityName: 'com.example.accountjsdemo.LoginAbility',
    };
    callback.onRequestRedirected(want);
  }

  authenticate(name: string, authType: string, callerBundleName: string,
    options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) {
    callback.onResult(appAccount.ResultCode.SUCCESS, {
      name: name,
      authType: authType,
      token: 'xxxxxx'
    });
  }
}
```

## Authenticator^8+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

认证器基类。

### createAccountImplicitly^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void

根据指定的账号所有者隐式地创建应用账号。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------------------------------------------|:-|:----------------|
|options|[CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9)|是|隐式创建账号的选项。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调对象，用于返回创建结果。|

### addAccountImplicitly^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addAccountImplicitly(authType: string, callerBundleName: string, options: { [key: string]: any }, callback: AuthenticatorCallback): void

根据指定的鉴权类型和可选项，隐式地添加应用账号。使用callback异步回调。
> 说明
>
> 从API version 8开始支持, 从API version 9开始废弃，建议使用[createAccountImplicitly](#createaccountimplicitly9-2)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------------|:--------------------------------------------------------|:-|:----------------------------|
|authType|string|是|应用账号的鉴权类型。自定义数据，最大长度为1024个字符。|
|callerBundleName|string|是|鉴权请求方的包名。|
|options|{[key: string]: any}|是|鉴权所需要的可选项。|
|callback|[AuthenticatorCallback](#authenticatorcallbackdeprecated)|是|认证器回调，用于返回鉴权结果。|

### auth^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

auth(name: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void

对应用账号进行鉴权以获取授权令牌。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|应用账号的鉴权类型。自定义数据，最大长度为1024个字符。|
|options|Record<string, Object>|是|鉴权所需要的可选项。|
|callback|[AuthCallback](#authcallback9)|是|回调对象，用于返回鉴权结果。|

### authenticate^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

authenticate(name: string, authType: string, callerBundleName: string, options: { [key: string]: any }, callback: AuthenticatorCallback): void

对应用账号进行鉴权，获取OAuth令牌。使用callback异步回调。
> 说明
>
> 从API version 8开始支持, 从API version 9开始废弃，建议使用[auth](#auth9-2)替代。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:---------------|:--------------------------------------------------------|:-|:----------------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|authType|string|是|应用账号的鉴权类型。自定义数据，最大长度为1024个字符。|
|callerBundleName|string|是|鉴权请求方的包名。|
|options|{[key: string]: any}|是|鉴权所需要的可选项。|
|callback|[AuthenticatorCallback](#authenticatorcallbackdeprecated)|是|认证器回调，用于返回鉴权结果。|

### verifyCredential^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void

验证应用账号的凭据。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|options|[VerifyCredentialOptions](#verifycredentialoptions9)|是|验证凭据的可选项。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调，用于返回验证结果。|

**示例：**

接口需组合使用，请查看[getRemoteObject](#getremoteobject9)中的示例。

### setProperties^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

setProperties(options: SetPropertiesOptions, callback: AuthCallback): void

设置认证器属性。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------|:-|:--------------|
|options|[SetPropertiesOptions](#setpropertiesoptions9)|是|设置属性的可选项。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调，用于返回设置结果。|

**示例：**

接口需组合使用，请查看[getRemoteObject](#getremoteobject9)中的示例。

### checkAccountLabels^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void

检查账号标签。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|labels|Array<string>|是|标签数组。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调，用于返回检查结果。|

**示例：**

接口需组合使用，请查看[getRemoteObject](#getremoteobject9)中的示例。

### checkAccountRemovable^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

checkAccountRemovable(name: string, callback: AuthCallback): void

判断账号是否可以删除。使用callback异步回调。

**系统能力：** SystemCapability.Account.AppAccount

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------|:-|:-------------------|
|name|string|是|应用账号的名称。最大长度为512个字符。|
|callback|[AuthCallback](#authcallback9)|是|认证器回调，用于返回判断结果。|

**示例：**

接口需组合使用，请查看[getRemoteObject](#getremoteobject9)中的示例。

### getRemoteObject^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRemoteObject(): rpc.RemoteObject

获取认证器的远程对象，不可以重载实现。

**系统能力：** SystemCapability.Account.AppAccount

**返回值：**

|类型|说明|
|:-------------------------------------------------------------------------------------------------------------|:-----------------------------|
|[rpc.RemoteObject](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-rpc#remoteobject)|认证器Authenticator的远程对象。用于跨进程通信。|

**示例：**

接口需组合使用，请查看[getRemoteObject](#getremoteobject9)中的示例。

**示例：**

```ts
import { rpc } from '@kit.IPCKit';
import { Want } from '@kit.AbilityKit';

class MyAuthenticator extends appAccount.Authenticator {
  verifyCredential(name: string,
    options: appAccount.VerifyCredentialOptions, callback: appAccount.AuthCallback) {
      let want: Want = {
        bundleName: 'com.example.accountjsdemo',
        abilityName: 'com.example.accountjsdemo.VerifyAbility',
        parameters: {
          name: name
        }
      };
      callback.onRequestRedirected(want);
  }

  setProperties(options: appAccount.SetPropertiesOptions, callback: appAccount.AuthCallback) {
    let want: Want = {
      bundleName: 'com.example.accountjsdemo',
      abilityName: 'com.example.accountjsdemo.SetPropertiesAbility',
      parameters: {
        options: options
      }
    };
    callback.onRequestRedirected(want);
  }

  checkAccountLabels(name: string, labels: string[], callback: appAccount.AuthCallback) {
    callback.onResult(0);
  }

  checkAccountRemovable(name: string, callback: appAccount.AuthCallback) {
    callback.onResult(0);
  }
}

export default {
  onConnect(want: Want): rpc.RemoteObject { // serviceAbility 生命周期函数, 需要放在serviceAbility中
    let authenticator = new MyAuthenticator();
    return authenticator.getRemoteObject();
  }
}
```

