1# @ohos.account.appAccount (Application Account Management) 2 3The **appAccount** module provides APIs for adding, deleting, modifying, and querying application account information, and supports inter-application authentication and distributed data synchronization. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10## Modules to Import 11 12```ts 13import { appAccount } from '@kit.BasicServicesKit'; 14``` 15 16 17## appAccount.createAppAccountManager 18 19createAppAccountManager(): AppAccountManager 20 21Creates an **AppAccountManager** object. 22 23**System capability**: SystemCapability.Account.AppAccount 24 25**Return value** 26 27| Type | Description | 28| ----------------- | ------------ | 29| AppAccountManager | **AppAccountManager** object created.| 30 31**Example** 32 ```ts 33 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 34 ``` 35 36## AppAccountManager 37 38Implements application account management. 39 40### createAccount<sup>9+</sup> 41 42createAccount(name: string, callback: AsyncCallback<void>): void 43 44Creates an application account with the given name. This API uses an asynchronous callback to return the result. 45 46**System capability**: SystemCapability.Account.AppAccount 47 48**Parameters** 49 50| Name | Type | Mandatory | Description | 51| -------- | ------------------------- | ----- | -------------------- | 52| name | string | Yes | Name of the application account to create. | 53| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 54 55**Error codes** 56 57| ID| Error Message| 58| ------- | ------- | 59| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 60| 12300001 | System service exception. | 61| 12300002 | Invalid name. | 62| 12300004 | Account already exists. | 63| 12300007 | The number of accounts reaches the upper limit. | 64 65**Example** 66 67 ```ts 68 import { BusinessError } from '@kit.BasicServicesKit'; 69 70 try { 71 appAccountManager.createAccount('WangWu', (err: BusinessError) => { 72 console.log('createAccount err: ' + JSON.stringify(err)); 73 }); 74 } catch (err) { 75 console.log('createAccount err: ' + JSON.stringify(err)); 76 } 77 ``` 78 79### createAccount<sup>9+</sup> 80 81createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void 82 83Creates an application account with custom data. This API uses an asynchronous callback to return the result. 84 85**System capability**: SystemCapability.Account.AppAccount 86 87**Parameters** 88 89| Name | Type | Mandatory | Description | 90| --------- | ------------------------- | ---- | ---------------------------------------- | 91| name | string | Yes | Name of the application account to create. | 92| options | [CreateAccountOptions](#createaccountoptions9) | Yes | Options for creating the application account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens).| 93| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 94 95**Error codes** 96 97| ID| Error Message| 98| ------- | ------- | 99| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 100| 12300001 | System service exception. | 101| 12300002 | Invalid name or options. | 102| 12300004 | Account already exists. | 103| 12300007 | The number of accounts reaches the upper limit. | 104 105**Example** 106 107 ```ts 108 import { BusinessError } from '@kit.BasicServicesKit'; 109 110 let options:appAccount.CreateAccountOptions = { 111 customData: { 112 age: '10' 113 } 114 } 115 try { 116 appAccountManager.createAccount('LiSi', options, (err: BusinessError) => { 117 if (err) { 118 console.log('createAccount failed, error: ' + JSON.stringify(err)); 119 } else { 120 console.log('createAccount successfully'); 121 } 122 }); 123 } catch(err) { 124 console.log('createAccount exception: ' + JSON.stringify(err)); 125 } 126 ``` 127 128### createAccount<sup>9+</sup> 129 130createAccount(name: string, options?: CreateAccountOptions): Promise<void> 131 132Creates an application account with custom data. This API uses a promise to return the result. 133 134**System capability**: SystemCapability.Account.AppAccount 135 136**Parameters** 137 138| Name | Type | Mandatory | Description | 139| --------- | ------ | ---- | ---------------------------------------- | 140| name | string | Yes | Name of the application account to create. | 141| options | [CreateAccountOptions](#createaccountoptions9) | No | Options for creating the application account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens). <br>By default, no value is passed in, which means no additional information needs to be added for the account.| 142 143**Return value** 144 145| Type | Description | 146| ------------------- | --------------------- | 147| Promise<void> | Promise that returns no value.| 148 149**Error codes** 150 151| ID| Error Message| 152| ------- | -------| 153| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 154| 12300001 | System service exception. | 155| 12300002 | Invalid name or options. | 156| 12300004 | Account already exists. | 157| 12300007 | The number of accounts reaches the upper limit. | 158 159**Example** 160 161 ```ts 162 import { BusinessError } from '@kit.BasicServicesKit'; 163 164 let options: appAccount.CreateAccountOptions = { 165 customData: { 166 age: '10' 167 } 168 } 169 try { 170 appAccountManager.createAccount('LiSi', options).then(() => { 171 console.log('createAccount successfully'); 172 }).catch((err: BusinessError) => { 173 console.log('createAccount failed, error: ' + JSON.stringify(err)); 174 }); 175 } catch(err) { 176 console.log('createAccount exception: ' + JSON.stringify(err)); 177 } 178 ``` 179 180### createAccountImplicitly<sup>9+</sup> 181 182createAccountImplicitly(owner: string, callback: AuthCallback): void 183 184Creates an application account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. 185 186**System capability**: SystemCapability.Account.AppAccount 187 188**Parameters** 189 190| Name | Type | Mandatory | Description | 191| -------- | --------------------- | ---- | ----------------------- | 192| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 193| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 194 195**Error codes** 196 197| ID| Error Message| 198| ------- | -------| 199| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 200| 12300001 | System service exception. | 201| 12300002 | Invalid owner. | 202| 12300007 | The number of accounts reaches the upper limit. | 203| 12300010 | Account service busy. | 204| 12300113 | Authenticator service not found. | 205| 12300114 | Authenticator service exception. | 206 207**Example** 208 209 ```ts 210 import { BusinessError } from '@kit.BasicServicesKit'; 211 import { Want, common } from '@kit.AbilityKit'; 212 213 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 214 215 function onResultCallback(code: number, result?: appAccount.AuthResult): void { 216 console.log('resultCode: ' + code); 217 console.log('result: ' + JSON.stringify(result)); 218 } 219 220 function onRequestRedirectedCallback(request: Want): void { 221 let wantInfo: Want = { 222 deviceId: '', 223 bundleName: 'com.example.accountjsdemo', 224 action: 'ohos.want.action.viewData', 225 entities: ['entity.system.default'], 226 } 227 context.startAbility(wantInfo).then(() => { 228 console.log('startAbility successfully'); 229 }).catch((err: BusinessError) => { 230 console.log('startAbility err: ' + JSON.stringify(err)); 231 }) 232 } 233 234 try { 235 appAccountManager.createAccountImplicitly('com.example.accountjsdemo', { 236 onResult: onResultCallback, 237 onRequestRedirected: onRequestRedirectedCallback 238 }); 239 } catch (err) { 240 console.log('createAccountImplicitly exception: ' + JSON.stringify(err)); 241 } 242 ``` 243 244### createAccountImplicitly<sup>9+</sup> 245 246createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 247 248Creates an application account implicitly based on the specified account owner and options. This API uses an asynchronous callback to return the result. 249 250**System capability**: SystemCapability.Account.AppAccount 251 252**Parameters** 253 254| Name | Type | Mandatory | Description | 255| -------- | --------------------- | ---- | ----------------------- | 256| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 257| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | 258| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 259 260**Error codes** 261 262| ID| Error Message| 263| ------- | ------- | 264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 265| 12300001 | System service exception. | 266| 12300002 | Invalid owner or options. | 267| 12300007 | The number of accounts reaches the upper limit. | 268| 12300010 | Account service busy. | 269| 12300113 | Authenticator service not found. | 270| 12300114 | Authenticator service exception. | 271 272**Example** 273 274 ```ts 275 import { BusinessError } from '@kit.BasicServicesKit'; 276 import { Want, common } from '@kit.AbilityKit'; 277 278 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 279 280 function onResultCallback(code: number, result?: appAccount.AuthResult): void { 281 console.log('resultCode: ' + code); 282 console.log('result: ' + JSON.stringify(result)); 283 } 284 285 function onRequestRedirectedCallback(request: Want): void { 286 let wantInfo: Want = { 287 deviceId: '', 288 bundleName: 'com.example.accountjsdemo', 289 action: 'ohos.want.action.viewData', 290 entities: ['entity.system.default'], 291 } 292 context.startAbility(wantInfo).then(() => { 293 console.log('startAbility successfully'); 294 }).catch((err: BusinessError) => { 295 console.log('startAbility err: ' + JSON.stringify(err)); 296 }) 297 } 298 299 let options: appAccount.CreateAccountImplicitlyOptions = { 300 authType: 'getSocialData', 301 requiredLabels: [ 'student' ] 302 }; 303 try { 304 appAccountManager.createAccountImplicitly('com.example.accountjsdemo', options, { 305 onResult: onResultCallback, 306 onRequestRedirected: onRequestRedirectedCallback 307 }); 308 } catch (err) { 309 console.log('createAccountImplicitly exception: ' + JSON.stringify(err)); 310 } 311 ``` 312 313### removeAccount<sup>9+</sup> 314 315removeAccount(name: string, callback: AsyncCallback<void>): void 316 317Removes an application account. This API uses an asynchronous callback to return the result. 318 319**System capability**: SystemCapability.Account.AppAccount 320 321**Parameters** 322 323| Name | Type | Mandatory | Description | 324| -------- | ------------------------- | ---- | ---------------- | 325| name | string | Yes | Name of the target application account. | 326| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 327 328**Error codes** 329 330| ID| Error Message| 331| ------- | ------- | 332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 333| 12300001 | System service exception. | 334| 12300002 | Invalid name. | 335| 12300003 | Account not found. | 336 337**Example** 338 339 ```ts 340 import { BusinessError } from '@kit.BasicServicesKit'; 341 342 try { 343 appAccountManager.removeAccount('ZhaoLiu', (err: BusinessError) => { 344 if (err) { 345 console.log('removeAccount failed, error: ' + JSON.stringify(err)); 346 } else { 347 console.log('removeAccount successfully'); 348 } 349 }); 350 } catch(err) { 351 console.log('removeAccount exception: ' + JSON.stringify(err)); 352 } 353 ``` 354 355### removeAccount<sup>9+</sup> 356 357removeAccount(name: string): Promise<void> 358 359Removes an application account. This API uses a promise to return the result. 360 361**System capability**: SystemCapability.Account.AppAccount 362 363**Parameters** 364 365| Name | Type | Mandatory | Description | 366| ---- | ------ | ---- | ----------- | 367| name | string | Yes | Name of the target application account.| 368 369**Return value** 370 371| Type | Description | 372| :------------------ | :-------------------- | 373| Promise<void> | Promise that returns no value.| 374 375**Error codes** 376 377| ID| Error Message| 378| ------- | ------- | 379| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 380| 12300001 | System service exception. | 381| 12300002 | Invalid name. | 382| 12300003 | Account not found. | 383 384**Example** 385 386 ```ts 387 import { BusinessError } from '@kit.BasicServicesKit'; 388 389 try { 390 appAccountManager.removeAccount('Lisi').then(() => { 391 console.log('removeAccount successfully'); 392 }).catch((err: BusinessError) => { 393 console.log('removeAccount failed, error: ' + JSON.stringify(err)); 394 }); 395 } catch (err) { 396 console.log('removeAccount exception: ' + JSON.stringify(err)); 397 } 398 ``` 399 400### setAppAccess<sup>9+</sup> 401 402setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void 403 404Sets the access to the data of an account for an application. This API uses an asynchronous callback to return the result. 405 406**System capability**: SystemCapability.Account.AppAccount 407 408**Parameters** 409 410| Name | Type | Mandatory | Description | 411| ------------ | ------------------------- | ---- | --------------------------------- | 412| name | string | Yes | Name of the target application account. | 413| bundleName | string | Yes | Bundle name of the application. | 414| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| 415| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 416 417**Error codes** 418 419| ID| Error Message| 420| ------- | -------| 421| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 422| 12300001 | System service exception. | 423| 12300002 | Invalid name or bundleName. | 424| 12300003 | Account not found. | 425| 12400005 | The size of authorization list reaches the upper limit. | 426 427**Example** 428 429 ```ts 430 import { BusinessError } from '@kit.BasicServicesKit'; 431 432 try { 433 appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true, (err: BusinessError) => { 434 if (err) { 435 console.log('setAppAccess failed: ' + JSON.stringify(err)); 436 } else { 437 console.log('setAppAccess successfully'); 438 } 439 }); 440 } catch (err) { 441 console.log('setAppAccess exception: ' + JSON.stringify(err)); 442 } 443 ``` 444 445### setAppAccess<sup>9+</sup> 446 447setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void> 448 449Sets the access to the data of an account for an application. This API uses a promise to return the result. 450 451**System capability**: SystemCapability.Account.AppAccount 452 453**Parameters** 454 455| Name | Type | Mandatory | Description | 456| ---------- | ------ | ---- | --------- | 457| name | string | Yes | Name of the target application account. | 458| bundleName | string | Yes | Bundle name of the application.| 459| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| 460 461**Return value** 462 463| Type | Description | 464| :------------------ | :-------------------- | 465| Promise<void> | Promise that returns no value.| 466 467**Error codes** 468 469| ID| Error Message| 470| ------- | -------| 471| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 472| 12300001 | System service exception. | 473| 12300002 | Invalid name or bundleName. | 474| 12300003 | Account not found. | 475| 12400005 | The size of authorization list reaches the upper limit. | 476 477**Example** 478 479 ```ts 480 import { BusinessError } from '@kit.BasicServicesKit'; 481 482 try { 483 appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true).then(() => { 484 console.log('setAppAccess successfully'); 485 }).catch((err: BusinessError) => { 486 console.log('setAppAccess failed: ' + JSON.stringify(err)); 487 }); 488 } catch (err) { 489 console.log('setAppAccess exception: ' + JSON.stringify(err)); 490 } 491 ``` 492 493### checkAppAccess<sup>9+</sup> 494 495checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void 496 497Checks whether an application can access the data of an account. This API uses an asynchronous callback to return the result. 498 499**System capability**: SystemCapability.Account.AppAccount 500 501**Parameters** 502 503| Name | Type | Mandatory | Description | 504| ---------- | ------------------------- | ---- | --------------------------------- | 505| name | string | Yes | Name of the target application account. | 506| bundleName | string | Yes | Bundle name of the application. | 507| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means the application can access the account data; the value **false** means the opposite.| 508 509**Error codes** 510 511| ID| Error Message| 512| ------- | ------- | 513| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 514| 12300001 | System service exception. | 515| 12300002 | Invalid name or bundleName. | 516| 12300003 | Account not found. | 517 518**Example** 519 520 ```ts 521 import { BusinessError } from '@kit.BasicServicesKit'; 522 523 try { 524 appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo', 525 (err: BusinessError, isAccessible: boolean) => { 526 if (err) { 527 console.log('checkAppAccess failed, error: ' + JSON.stringify(err)); 528 } else { 529 console.log('checkAppAccess successfully'); 530 } 531 }); 532 } catch (err) { 533 console.log('checkAppAccess exception: ' + JSON.stringify(err)); 534 } 535 ``` 536 537### checkAppAccess<sup>9+</sup> 538 539checkAppAccess(name: string, bundleName: string): Promise<boolean> 540 541Checks whether an application can access the data of an account. This API uses a promise to return the result. 542 543**System capability**: SystemCapability.Account.AppAccount 544 545**Parameters** 546 547| Name | Type | Mandatory | Description | 548| ---------- | ------ | ---- | --------- | 549| name | string | Yes | Name of the target application account. | 550| bundleName | string | Yes | Bundle name of the application.| 551 552**Return value** 553 554| Type | Description | 555| ------------------- | --------------------- | 556| Promise<boolean> | Promise used to return the result. The value **true** means the application can access the account data; the value **false** means the opposite.| 557 558**Error codes** 559 560| ID| Error Message| 561| ------- | -------| 562| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 563| 12300001 | System service exception. | 564| 12300002 | Invalid name or bundleName. | 565| 12300003 | Account not found. | 566 567**Example** 568 569 ```ts 570 import { BusinessError } from '@kit.BasicServicesKit'; 571 572 try { 573 appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo').then((isAccessible: boolean) => { 574 console.log('checkAppAccess successfully, isAccessible: ' + isAccessible); 575 }).catch((err: BusinessError) => { 576 console.log('checkAppAccess failed, error: ' + JSON.stringify(err)); 577 }); 578 } catch (err) { 579 console.log('checkAppAccess exception: ' + JSON.stringify(err)); 580 } 581 ``` 582 583### setDataSyncEnabled<sup>9+</sup> 584 585setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void 586 587Sets data synchronization for an application account. This API uses an asynchronous callback to return the result. 588 589**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 590 591**System capability**: SystemCapability.Account.AppAccount 592 593**Parameters** 594 595| Name | Type | Mandatory | Description | 596| -------- | ------------------------- | ---- | ------------------------- | 597| name | string | Yes | Name of the target application account. | 598| isEnabled | boolean | Yes | Whether to enable data synchronization. | 599| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 600 601**Error codes** 602 603| ID| Error Message| 604| ------- | -------| 605| 201 | Permission denied.| 606| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 607| 12300001 | System service exception. | 608| 12300002 | Invalid name. | 609| 12300003 | Account not found. | 610 611**Example** 612 613 ```ts 614 import { BusinessError } from '@kit.BasicServicesKit'; 615 616 try { 617 appAccountManager.setDataSyncEnabled('ZhangSan', true, (err: BusinessError) => { 618 console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); 619 }); 620 } catch (err) { 621 console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); 622 } 623 ``` 624 625### setDataSyncEnabled<sup>9+</sup> 626 627setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void> 628 629Sets data synchronization for an application account. This API uses a promise to return the result. 630 631**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 632 633**System capability**: SystemCapability.Account.AppAccount 634 635**Parameters** 636 637| Name | Type | Mandatory | Description | 638| -------- | ------- | ---- | ----------- | 639| name | string | Yes | Name of the target application account. | 640| isEnabled | boolean | Yes | Whether to enable data synchronization.| 641 642**Return value** 643 644| Type | Description | 645| :------------------ | :-------------------- | 646| Promise<void> | Promise that returns no value.| 647 648**Error codes** 649 650| ID| Error Message| 651| ------- | ------- | 652| 201 | Permission denied.| 653| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 654| 12300001 | System service exception. | 655| 12300002 | Invalid name. | 656| 12300003 | Account not found. | 657 658**Example** 659 660 ```ts 661 import { BusinessError } from '@kit.BasicServicesKit'; 662 663 try { 664 appAccountManager .setDataSyncEnabled('ZhangSan', true).then(() => { 665 console.log('setDataSyncEnabled Success'); 666 }).catch((err: BusinessError) => { 667 console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); 668 }); 669 } catch (err) { 670 console.log('setDataSyncEnabled err: ' + JSON.stringify(err)); 671 } 672 ``` 673 674### checkDataSyncEnabled<sup>9+</sup> 675 676checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void 677 678Checks whether data synchronization is enabled for an application account. This API uses an asynchronous callback to return the result. 679 680**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 681 682**System capability**: SystemCapability.Account.AppAccount 683 684**Parameters** 685 686| Name | Type | Mandatory | Description | 687| -------- | ---------------------------- | ---- | --------------------- | 688| name | string | Yes | Name of the target application account. | 689| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means data synchronization is enabled for the application account; the value **false** means the opposite.| 690 691**Error codes** 692 693| ID| Error Message| 694| ------- | ------- | 695| 201 | Permission denied.| 696| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 697| 12300001 | System service exception. | 698| 12300002 | Invalid name. | 699| 12300003 | Account not found. | 700 701**Example** 702 703 ```ts 704 import { BusinessError } from '@kit.BasicServicesKit'; 705 706 try { 707 appAccountManager.checkDataSyncEnabled('ZhangSan', (err: BusinessError, isEnabled: boolean) => { 708 if (err) { 709 console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err)); 710 } else { 711 console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled); 712 } 713 }); 714 } catch (err) { 715 console.log('checkDataSyncEnabled err: ' + JSON.stringify(err)); 716 } 717 ``` 718 719### checkDataSyncEnabled<sup>9+</sup> 720 721checkDataSyncEnabled(name: string): Promise<boolean> 722 723Checks whether data synchronization is enabled for an application account. This API uses a promise to return the result. 724 725**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 726 727**System capability**: SystemCapability.Account.AppAccount 728 729**Parameters** 730 731| Name | Type | Mandatory | Description | 732| ---- | ------ | ---- | ------- | 733| name | string | Yes | Name of the target application account.| 734 735**Return value** 736 737| Type | Description | 738| :--------------------- | :-------------------- | 739| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the application account; the value **false** means the opposite.| 740 741**Error codes** 742 743| ID| Error Message| 744| ------- | -------| 745| 201 | Permission denied.| 746| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 747| 12300001 | System service exception. | 748| 12300002 | Invalid name. | 749| 12300003 | Account not found. | 750 751**Example** 752 753 ```ts 754 import { BusinessError } from '@kit.BasicServicesKit'; 755 756 try { 757 appAccountManager.checkDataSyncEnabled('ZhangSan').then((isEnabled: boolean) => { 758 console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled); 759 }).catch((err: BusinessError) => { 760 console.log('checkDataSyncEnabled failed, err: ' + JSON.stringify(err)); 761 }); 762 } catch (err) { 763 console.log('checkDataSyncEnabled err: ' + JSON.stringify(err)); 764 } 765 ``` 766 767### setCredential<sup>9+</sup> 768 769setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void 770 771Sets a credential for an application account. This API uses an asynchronous callback to return the result. 772 773**System capability**: SystemCapability.Account.AppAccount 774 775**Parameters** 776 777| Name | Type | Mandatory | Description | 778| -------------- | ------------------------- | ---- | ------------- | 779| name | string | Yes | Name of the target application account. | 780| credentialType | string | Yes | Type of the credential to set. | 781| credential | string | Yes | Credential value. | 782| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the credential is set successfully, **err** is **null**. Otherwise, **err** is an error object.| 783 784**Error codes** 785 786| ID| Error Message| 787| ------- | -------| 788| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 789| 12300001 | System service exception. | 790| 12300002 | Invalid name, credentialType or credential. | 791| 12300003 | Account not found. | 792 793**Example** 794 795 ```ts 796 import { BusinessError } from '@kit.BasicServicesKit'; 797 798 try { 799 appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx', (err: BusinessError) => { 800 if (err) { 801 console.log('setCredential failed, error: ' + JSON.stringify(err)); 802 } else { 803 console.log('setCredential successfully'); 804 } 805 }); 806 } catch (err) { 807 console.log('setCredential exception: ' + JSON.stringify(err)); 808 } 809 ``` 810 811### setCredential<sup>9+</sup> 812 813setCredential(name: string, credentialType: string, credential: string): Promise<void> 814 815Sets a credential for an application account. This API uses a promise to return the result. 816 817**System capability**: SystemCapability.Account.AppAccount 818 819**Parameters** 820 821| Name | Type | Mandatory | Description | 822| -------------- | ------ | ---- | ---------- | 823| name | string | Yes | Name of the target application account. | 824| credentialType | string | Yes | Type of the credential to set.| 825| credential | string | Yes | Credential value. | 826 827**Return value** 828 829| Type | Description | 830| :------------------ | :-------------------- | 831| Promise<void> | Promise that returns no value.| 832 833**Error codes** 834 835| ID| Error Message| 836| ------- | -------| 837| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 838| 12300001 | System service exception. | 839| 12300002 | Invalid name, credentialType or credential. | 840| 12300003 | Account not found. | 841 842**Example** 843 844 ```ts 845 import { BusinessError } from '@kit.BasicServicesKit'; 846 847 try { 848 appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx').then(() => { 849 console.log('setCredential successfully'); 850 }).catch((err: BusinessError) => { 851 console.log('setCredential failed, error: ' + JSON.stringify(err)); 852 }); 853 } catch (err) { 854 console.log('setCredential exception: ' + JSON.stringify(err)); 855 } 856 ``` 857 858### getCredential<sup>9+</sup> 859 860getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 861 862Obtains the credential of an application account. This API uses an asynchronous callback to return the result. 863 864**System capability**: SystemCapability.Account.AppAccount 865 866**Parameters** 867 868| Name | Type | Mandatory | Description | 869| -------------- | --------------------------- | ---- | -------------- | 870| name | string | Yes | Name of the target application account. | 871| credentialType | string | Yes | Type of the credential to obtain.| 872| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| 873 874**Error codes** 875 876| ID| Error Message| 877| ------- | ------- | 878| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 879| 12300001 | System service exception. | 880| 12300002 | Invalid name or credentialType. | 881| 12300003 | Account not found. | 882| 12300102 | Credential not found. | 883 884**Example** 885 886 ```ts 887 import { BusinessError } from '@kit.BasicServicesKit'; 888 889 try { 890 appAccountManager.getCredential('ZhangSan', 'PIN_SIX', (err: BusinessError, result: string) => { 891 if (err) { 892 console.log('getCredential failed, error: ' + JSON.stringify(err)); 893 } else { 894 console.log('getCredential successfully, result: ' + result); 895 } 896 }); 897 } catch (err) { 898 console.log('getCredential err: ' + JSON.stringify(err)); 899 } 900 ``` 901 902### getCredential<sup>9+</sup> 903 904getCredential(name: string, credentialType: string): Promise<string> 905 906Obtains the credential of an application account. This API uses a promise to return the result. 907 908**System capability**: SystemCapability.Account.AppAccount 909 910**Parameters** 911 912| Name | Type | Mandatory | Description | 913| -------------- | ------ | ---- | ---------- | 914| name | string | Yes | Name of the target application account.| 915| credentialType | string | Yes | Type of the credential to obtain.| 916 917**Return value** 918 919| Type | Description | 920| :-------------------- | :-------------------- | 921| Promise<string> | Promise used to return the credential obtained.| 922 923**Error codes** 924 925| ID| Error Message| 926| ------- | ------- | 927| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 928| 12300001 | System service exception. | 929| 12300002 | Invalid name or credentialType. | 930| 12300003 | Account not found. | 931| 12300102 | Credential not found. | 932 933**Example** 934 935 ```ts 936 import { BusinessError } from '@kit.BasicServicesKit'; 937 938 try { 939 appAccountManager.getCredential('ZhangSan', 'PIN_SIX').then((credential: string) => { 940 console.log('getCredential successfully, credential: ' + credential); 941 }).catch((err: BusinessError) => { 942 console.log('getCredential failed, error: ' + JSON.stringify(err)); 943 }); 944 } catch (err) { 945 console.log('getCredential exception: ' + JSON.stringify(err)); 946 } 947 ``` 948 949### setCustomData<sup>9+</sup> 950 951setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void 952 953Sets custom data for an application account. This API uses an asynchronous callback to return the result. 954 955**System capability**: SystemCapability.Account.AppAccount 956 957**Parameters** 958 959| Name | Type | Mandatory | Description | 960| -------- | ------------------------- | ---- | ----------------- | 961| name | string | Yes | Name of the target application account.| 962| key | string | Yes | Key of the custom data to set.| 963| value | string | Yes | Value of the custom data to set.| 964| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 965 966**Error codes** 967 968| ID| Error Message| 969| ------- | -------| 970| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 971| 12300001 | System service exception. | 972| 12300002 | Invalid name, key or value. | 973| 12300003 | Account not found. | 974| 12400003 | The number of custom data reaches the upper limit. | 975 976**Example** 977 978 ```ts 979 import { BusinessError } from '@kit.BasicServicesKit'; 980 981 try { 982 appAccountManager.setCustomData('ZhangSan', 'age', '12', (err: BusinessError) => { 983 if (err) { 984 console.log('setCustomData failed, error: ' + JSON.stringify(err)); 985 } else { 986 console.log('setCustomData successfully'); 987 } 988 }); 989 } catch (err) { 990 console.log('setCustomData exception: ' + JSON.stringify(err)); 991 } 992 ``` 993 994### setCustomData<sup>9+</sup> 995 996setCustomData(name: string, key: string, value: string): Promise<void> 997 998Sets custom data for an application account. This API uses a promise to return the result. 999 1000**System capability**: SystemCapability.Account.AppAccount 1001 1002**Parameters** 1003 1004| Name | Type| Mandatory | Description | 1005| ----- | ------ | ---- | ----------------- | 1006| name | string | Yes | Name of the target application account. | 1007| key | string | Yes | Key of the custom data to set.| 1008| value | string | Yes | Value of the custom data to set.| 1009 1010**Return value** 1011 1012| Type | Description | 1013| :------------------ | :-------------------- | 1014| Promise<void> | Promise that returns no value.| 1015 1016**Error codes** 1017 1018| ID| Error Message| 1019| ------- | -------| 1020| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1021| 12300001 | System service exception. | 1022| 12300002 | Invalid name, key or value. | 1023| 12300003 | Account not found. | 1024| 12400003 | The number of custom data reaches the upper limit. | 1025 1026**Example** 1027 1028 ```ts 1029 import { BusinessError } from '@kit.BasicServicesKit'; 1030 1031 try { 1032 appAccountManager.setCustomData('ZhangSan', 'age', '12').then(() => { 1033 console.log('setCustomData successfully'); 1034 }).catch((err: BusinessError) => { 1035 console.log('setCustomData failed, error: ' + JSON.stringify(err)); 1036 }); 1037 } catch (err) { 1038 console.log('setCustomData exception: ' + JSON.stringify(err)); 1039 } 1040 ``` 1041 1042### getCustomData<sup>9+</sup> 1043 1044getCustomData(name: string, key: string, callback: AsyncCallback<string>): void 1045 1046Obtains the custom data of an application account based on the specified key. This API uses an asynchronous callback to return the result. 1047 1048**System capability**: SystemCapability.Account.AppAccount 1049 1050**Parameters** 1051 1052| Name | Type | Mandatory | Description | 1053| -------- | --------------------------- | ----- | ------------------------ | 1054| name | string | Yes | Name of the target application account. | 1055| key | string | Yes | Key of the custom data to obtain. | 1056| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the custom data value obtained. Otherwise, **err** is an error object.| 1057 1058**Error codes** 1059 1060| ID| Error Message| 1061| ------- | -------| 1062| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1063| 12300001 | System service exception. | 1064| 12300002 | Invalid name or key. | 1065| 12300003 | Account not found. | 1066| 12400002 | Custom data not found. | 1067 1068**Example** 1069 1070 ```ts 1071 import { BusinessError } from '@kit.BasicServicesKit'; 1072 1073 try { 1074 appAccountManager.getCustomData('ZhangSan', 'age', (err: BusinessError, data: string) => { 1075 if (err) { 1076 console.log('getCustomData failed, error: ' + err); 1077 } else { 1078 console.log('getCustomData successfully, data: ' + data); 1079 } 1080 }); 1081 } catch (err) { 1082 console.log('getCustomData exception: ' + JSON.stringify(err)); 1083 } 1084 ``` 1085 1086### getCustomData<sup>9+</sup> 1087 1088getCustomData(name: string, key: string): Promise<string> 1089 1090Obtains the custom data of an application account based on the specified key. This API uses a promise to return the result. 1091 1092**System capability**: SystemCapability.Account.AppAccount 1093 1094**Parameters** 1095 1096| Name | Type | Mandatory | Description | 1097| ---- | ------ | ---- | --------- | 1098| name | string | Yes | Name of the target application account. | 1099| key | string | Yes | Key of the custom data to obtain.| 1100 1101**Return value** 1102 1103| Type | Description | 1104| --------------------- | --------------------- | 1105| Promise<string> | Promise used to return the custom data value obtained.| 1106 1107**Error codes** 1108 1109| ID| Error Message| 1110| ------- | -------| 1111| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1112| 12300001 | System service exception. | 1113| 12300002 | Invalid name or key. | 1114| 12300003 | Account not found. | 1115| 12400002 | Custom data not found. | 1116 1117**Example** 1118 1119 ```ts 1120 import { BusinessError } from '@kit.BasicServicesKit'; 1121 1122 try { 1123 appAccountManager.getCustomData('ZhangSan', 'age').then((data: string) => { 1124 console.log('getCustomData successfully, data: ' + data); 1125 }).catch((err: BusinessError) => { 1126 console.log('getCustomData failed, error: ' + JSON.stringify(err)); 1127 }); 1128 } catch (err) { 1129 console.log('getCustomData exception: ' + JSON.stringify(err)); 1130 } 1131 ``` 1132 1133### getCustomDataSync<sup>9+</sup> 1134 1135getCustomDataSync(name: string, key: string): string; 1136 1137Obtains the custom data of an application account based on the specified key. The API returns the result synchronously. 1138 1139**System capability**: SystemCapability.Account.AppAccount 1140 1141**Parameters** 1142 1143| Name | Type | Mandatory | Description | 1144| ---- | ------ | ---- | --------- | 1145| name | string | Yes | Name of the target application account. | 1146| key | string | Yes | Key of the custom data to obtain.| 1147 1148**Return value** 1149 1150| Type | Description | 1151| --------------------- | --------------------- | 1152| string | Value of the custom data obtained.| 1153 1154**Error codes** 1155 1156| ID| Error Message| 1157| ------- | -------| 1158| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1159| 12300001 | System service exception. | 1160| 12300002 | Invalid name or key. | 1161| 12300003 | Account not found. | 1162| 12400002 | Custom data not found. | 1163 1164**Example** 1165 1166 ```ts 1167 try { 1168 let value = appAccountManager.getCustomDataSync('ZhangSan', 'age'); 1169 console.info('getCustomDataSync successfully, vaue: ' + value); 1170 } catch (err) { 1171 console.error('getCustomDataSync failed, error: ' + JSON.stringify(err)); 1172 } 1173 ``` 1174 1175### getAllAccounts<sup>9+</sup> 1176 1177getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 1178 1179Obtains information about all accessible application accounts. This API uses an asynchronous callback to return the result. 1180 1181**System capability**: SystemCapability.Account.AppAccount 1182 1183**Parameters** 1184 1185| Name | Type | Mandatory | Description | 1186| -------- | ---------------------------------------- | ---- | --------- | 1187| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible application accounts. Otherwise, **err** is an error object.| 1188 1189**Error codes** 1190 1191| ID| Error Message| 1192| ------- | -------| 1193| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1194| 12300001 | System service exception. | 1195 1196**Example** 1197 1198 ```ts 1199 import { BusinessError } from '@kit.BasicServicesKit'; 1200 1201 try { 1202 appAccountManager.getAllAccounts((err: BusinessError, data: appAccount.AppAccountInfo[]) => { 1203 if (err) { 1204 console.debug('getAllAccounts failed, error: ' + JSON.stringify(err)); 1205 } else { 1206 console.debug('getAllAccounts successfully'); 1207 } 1208 }); 1209 } catch (err) { 1210 console.debug('getAllAccounts exception: ' + JSON.stringify(err)); 1211 } 1212 ``` 1213 1214### getAllAccounts<sup>9+</sup> 1215 1216getAllAccounts(): Promise<Array<AppAccountInfo>> 1217 1218Obtains information about all accessible application accounts. This API uses a promise to return the result. 1219 1220**System capability**: SystemCapability.Account.AppAccount 1221 1222**Return value** 1223 1224| Type | Description | 1225| ---------------------------------------- | --------------------- | 1226| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return information about all accessible accounts.| 1227 1228**Error codes** 1229 1230| ID| Error Message| 1231| ------- | -------| 1232| 12300001 | System service exception. | 1233 1234**Example** 1235 1236 ```ts 1237 import { BusinessError } from '@kit.BasicServicesKit'; 1238 1239 try { 1240 appAccountManager.getAllAccounts().then((data: appAccount.AppAccountInfo[]) => { 1241 console.debug('getAllAccounts successfully'); 1242 }).catch((err: BusinessError) => { 1243 console.debug('getAllAccounts failed, error: ' + JSON.stringify(err)); 1244 }); 1245 } catch (err) { 1246 console.debug('getAllAccounts exception: ' + JSON.stringify(err)); 1247 } 1248 ``` 1249 1250### getAccountsByOwner<sup>9+</sup> 1251 1252getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void 1253 1254Obtains the application accounts that can be accessed by the invoker based on the application account owner. This API uses an asynchronous callback to return the result. 1255 1256**System capability**: SystemCapability.Account.AppAccount 1257 1258**Parameters** 1259 1260| Name | Type | Mandatory | Description | 1261| -------- | ---------------------------------------- | ---- | --------- | 1262| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 1263| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is null and **data** is the application account information obtained. Otherwise, **err** is an error object.| 1264 1265**Error codes** 1266 1267| ID| Error Message| 1268| ------- | -------| 1269| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1270| 12300001 | System service exception. | 1271| 12300002 | Invalid owner. | 1272 1273**Example** 1274 1275 ```ts 1276 import { BusinessError } from '@kit.BasicServicesKit'; 1277 1278 try { 1279 appAccountManager.getAccountsByOwner('com.example.accountjsdemo2', 1280 (err: BusinessError, data: appAccount.AppAccountInfo[]) => { 1281 if (err) { 1282 console.debug('getAccountsByOwner failed, error:' + JSON.stringify(err)); 1283 } else { 1284 console.debug('getAccountsByOwner successfully, data:' + JSON.stringify(data)); 1285 } 1286 }); 1287 } catch (err) { 1288 console.debug('getAccountsByOwner exception:' + JSON.stringify(err)); 1289 } 1290 ``` 1291 1292### getAccountsByOwner<sup>9+</sup> 1293 1294getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>> 1295 1296Obtains the application accounts that can be accessed by the invoker based on the application account owner. This API uses a promise to return the result. 1297 1298**System capability**: SystemCapability.Account.AppAccount 1299 1300**Parameters** 1301 1302| Name | Type | Mandatory | Description | 1303| ----- | ------ | ---- | ------ | 1304| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 1305 1306**Return value** 1307 1308| Type | Description | 1309| ---------------------------------------- | --------------------- | 1310| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the application account information obtained.| 1311 1312**Error codes** 1313 1314| ID| Error Message| 1315| ------- | -------| 1316| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1317| 12300001 | System service exception. | 1318| 12300002 | Invalid owner. | 1319 1320**Example** 1321 1322 ```ts 1323 import { BusinessError } from '@kit.BasicServicesKit'; 1324 1325 try { 1326 appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then(( 1327 data: appAccount.AppAccountInfo[]) => { 1328 console.debug('getAccountsByOwner successfully, data: ' + JSON.stringify(data)); 1329 }).catch((err: BusinessError) => { 1330 console.debug('getAccountsByOwner failed, error: ' + JSON.stringify(err)); 1331 }); 1332 } catch (err) { 1333 console.debug('getAccountsByOwner exception: ' + JSON.stringify(err)); 1334 } 1335 ``` 1336 1337### on('accountChange')<sup>9+</sup> 1338 1339on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 1340 1341Subscribes to account information changes of apps. 1342 1343**System capability**: SystemCapability.Account.AppAccount 1344 1345**Parameters** 1346 1347| Name | Type | Mandatory | Description | 1348| -------- | ---------------------------------------- | ---- | ------------------------------ | 1349| type | 'accountChange' | Yes | Event type to subscribe to. The value is **'accountChange'**. An event will be reported when the account information of the target application changes.| 1350| owners | Array<string> | Yes | application bundle names of the account. | 1351| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback registered to return the list of changed application accounts. | 1352 1353**Error codes** 1354 1355| ID| Error Message| 1356| ------- | ------- | 1357| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1358| 12300001 | System service exception. | 1359| 12300002 | Invalid type or owners. | 1360 1361**Example** 1362 1363 ```ts 1364 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 1365 console.log('receive change data:' + JSON.stringify(data)); 1366 } 1367 try{ 1368 appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback); 1369 } catch(err) { 1370 console.error('on accountChange failed, error:' + JSON.stringify(err)); 1371 } 1372 ``` 1373 1374### off('accountChange')<sup>9+</sup> 1375 1376off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void 1377 1378Unsubscribes from account information changes. 1379 1380**System capability**: SystemCapability.Account.AppAccount 1381 1382**Parameters** 1383 1384| Name | Type | Mandatory | Description | 1385| -------- | -------------------------------- | ---- | ------------ | 1386| type | 'accountChange' | Yes | Event type to unsubscribe from. The value is **'accountChange'**. | 1387| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | No | Callback to unregister. By default, no value is passed, which means to unregister all callbacks for the specified event.| 1388 1389**Error codes** 1390 1391| ID| Error Message| 1392| ------- | -------| 1393| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1394| 12300001 | System service exception. | 1395| 12300002 | Invalid type. | 1396 1397**Example** 1398 1399 ```ts 1400 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 1401 console.log('receive change data:' + JSON.stringify(data)); 1402 } 1403 try{ 1404 appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback); 1405 } catch(err) { 1406 console.error('on accountChange failed, error:' + JSON.stringify(err)); 1407 } 1408 try{ 1409 appAccountManager.off('accountChange', changeOnCallback); 1410 } 1411 catch(err){ 1412 console.error('off accountChange failed, error:' + JSON.stringify(err)); 1413 } 1414 ``` 1415 1416### auth<sup>9+</sup> 1417 1418auth(name: string, owner: string, authType: string, callback: AuthCallback): void 1419 1420Authenticates an application account. This API uses an asynchronous callback to return the result. 1421 1422**System capability**: SystemCapability.Account.AppAccount 1423 1424**Parameters** 1425 1426| Name | Type | Mandatory | Description | 1427| -------- | --------------------- | ---- | --------------- | 1428| name | string | Yes | Name of the target application account. | 1429| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 1430| authType | string | Yes | Authentication type. | 1431| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 1432 1433**Error codes** 1434 1435| ID| Error Message| 1436| ------- | -------| 1437| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1438| 12300001 | System service exception. | 1439| 12300002 | Invalid name, owner or authType. | 1440| 12300003 | Account not found. | 1441| 12300010 | Account service busy. | 1442| 12300113 | Authenticator service not found. | 1443| 12300114 | Authenticator service exception. | 1444 1445**Example** 1446 1447 ```ts 1448 import { BusinessError } from '@kit.BasicServicesKit'; 1449 import { Want, common } from '@kit.AbilityKit'; 1450 1451 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 1452 1453 function onResultCallback(code: number, authResult?: appAccount.AuthResult): void { 1454 console.log('resultCode: ' + code); 1455 console.log('authResult: ' + JSON.stringify(authResult)); 1456 } 1457 1458 function onRequestRedirectedCallback(request: Want): void { 1459 let wantInfo: Want = { 1460 deviceId: '', 1461 bundleName: 'com.example.accountjsdemo', 1462 action: 'ohos.want.action.viewData', 1463 entities: ['entity.system.default'], 1464 } 1465 context.startAbility(wantInfo).then(() => { 1466 console.log('startAbility successfully'); 1467 }).catch((err: BusinessError) => { 1468 console.log('startAbility err: ' + JSON.stringify(err)); 1469 }) 1470 } 1471 1472 try { 1473 appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', { 1474 onResult: onResultCallback, 1475 onRequestRedirected: onRequestRedirectedCallback 1476 }); 1477 } catch (err) { 1478 console.log('auth exception: ' + JSON.stringify(err)); 1479 } 1480 ``` 1481 1482### auth<sup>9+</sup> 1483 1484auth(name: string, owner: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void 1485 1486Authenticates an application account. This API uses an asynchronous callback to return the result. 1487 1488**System capability**: SystemCapability.Account.AppAccount 1489 1490**Parameters** 1491 1492| Name | Type | Mandatory | Description | 1493| -------- | --------------------- | ---- | --------------- | 1494| name | string | Yes | Name of the target application account. | 1495| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 1496| authType | string | Yes | Authentication type. | 1497| options | Record<string, Object> | Yes | Options for the authentication. | 1498| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 1499 1500**Error codes** 1501 1502| ID| Error Message| 1503| ------- | -------| 1504| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1505| 12300001 | System service exception. | 1506| 12300002 | Invalid name, owner, authType or options. | 1507| 12300003 | Account not found. | 1508| 12300010 | Account service busy. | 1509| 12300113 | Authenticator service not found. | 1510| 12300114 | Authenticator service exception. | 1511 1512**Example** 1513 1514 ```ts 1515 import { BusinessError } from '@kit.BasicServicesKit'; 1516 import { Want, common } from '@kit.AbilityKit'; 1517 1518 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 1519 1520 function onResultCallback(code: number, authResult?: appAccount.AuthResult): void { 1521 console.log('resultCode: ' + code); 1522 console.log('authResult: ' + JSON.stringify(authResult)); 1523 } 1524 1525 function onRequestRedirectedCallback(request: Want): void { 1526 let wantInfo: Want = { 1527 deviceId: '', 1528 bundleName: 'com.example.accountjsdemo', 1529 action: 'ohos.want.action.viewData', 1530 entities: ['entity.system.default'], 1531 } 1532 context.startAbility(wantInfo).then(() => { 1533 console.log('startAbility successfully'); 1534 }).catch((err: BusinessError) => { 1535 console.log('startAbility err: ' + JSON.stringify(err)); 1536 }) 1537 } 1538 1539 let options: Record<string, Object> = { 1540 'password': 'xxxx', 1541 }; 1542 try { 1543 appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, { 1544 onResult: onResultCallback, 1545 onRequestRedirected: onRequestRedirectedCallback 1546 }); 1547 } catch (err) { 1548 console.log('auth exception: ' + JSON.stringify(err)); 1549 } 1550 ``` 1551 1552### getAuthToken<sup>9+</sup> 1553 1554getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 1555 1556Obtains the authorization token of the specified authentication type for an application account. This API uses an asynchronous callback to return the result. 1557 1558**System capability**: SystemCapability.Account.AppAccount 1559 1560**Parameters** 1561 1562| Name | Type | Mandatory | Description | 1563| -------- | --------------------------- | ---- | ----------- | 1564| name | string | Yes | Name of the target application account. | 1565| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 1566| authType | string | Yes | Authentication type. | 1567| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | 1568 1569**Error codes** 1570 1571| ID| Error Message| 1572| ------- | -------| 1573| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1574| 12300001 | System service exception. | 1575| 12300002 | Invalid name, owner or authType. | 1576| 12300003 | Account not found. | 1577| 12300107 | AuthType not found. | 1578 1579**Example** 1580 1581 ```ts 1582 import { BusinessError } from '@kit.BasicServicesKit'; 1583 1584 try { 1585 appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 1586 (err: BusinessError, token: string) => { 1587 if (err) { 1588 console.log('getAuthToken failed, error: ' + JSON.stringify(err)); 1589 } else { 1590 console.log('getAuthToken successfully, token: ' + token); 1591 } 1592 }); 1593 } catch (err) { 1594 console.log('getAuthToken exception: ' + JSON.stringify(err)); 1595 } 1596 ``` 1597 1598### getAuthToken<sup>9+</sup> 1599 1600getAuthToken(name: string, owner: string, authType: string): Promise<string> 1601 1602Obtains the authorization token of the specified authentication type for an application account. This API uses a promise to return the result. 1603 1604**System capability**: SystemCapability.Account.AppAccount 1605 1606**Parameters** 1607 1608| Name | Type | Mandatory | Description | 1609| -------- | ------ | ---- | ----------- | 1610| name | string | Yes | Name of the target application account. | 1611| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 1612| authType | string | Yes | Authentication type. | 1613 1614**Return value** 1615 1616| Type | Description | 1617| --------------------- | --------------------- | 1618| Promise<string> | Promise used to return the authorization token obtained.| 1619 1620**Error codes** 1621 1622| ID| Error Message| 1623| ------- | ------- | 1624| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1625| 12300001 | System service exception. | 1626| 12300002 | Invalid name, owner or authType. | 1627| 12300003 | Account not found. | 1628| 12300107 | AuthType not found. | 1629 1630**Example** 1631 1632 ```ts 1633 import { BusinessError } from '@kit.BasicServicesKit'; 1634 1635 try { 1636 appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token: string) => { 1637 console.log('getAuthToken successfully, token: ' + token); 1638 }).catch((err: BusinessError) => { 1639 console.log('getAuthToken failed, error: ' + JSON.stringify(err)); 1640 }); 1641 } catch (err) { 1642 console.log('getAuthToken exception: ' + JSON.stringify(err)); 1643 } 1644 ``` 1645 1646### setAuthToken<sup>9+</sup> 1647 1648setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 1649 1650Sets an authorization token of the specific authentication type for an application account. This API uses an asynchronous callback to return the result. 1651 1652**System capability**: SystemCapability.Account.AppAccount 1653 1654**Parameters** 1655 1656| Name | Type | Mandatory | Description | 1657| -------- | ------------------------- | ---- | -------- | 1658| name | string | Yes | Name of the target application account.| 1659| authType | string | Yes | Authentication type. | 1660| token | string | Yes | Authorization token to set.| 1661| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1662 1663**Error codes** 1664 1665| ID| Error Message| 1666| ------- | -------| 1667| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1668| 12300001 | System service exception. | 1669| 12300002 | Invalid name, authType or token. | 1670| 12300003 | Account not found. | 1671| 12400004 | The number of tokens reaches the upper limit. | 1672 1673**Example** 1674 1675 ```ts 1676 import { BusinessError } from '@kit.BasicServicesKit'; 1677 1678 try { 1679 appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => { 1680 if (err) { 1681 console.log('setAuthToken failed, error: ' + JSON.stringify(err)); 1682 } else { 1683 console.log('setAuthToken successfully'); 1684 } 1685 }); 1686 } catch (err) { 1687 console.log('setAuthToken exception: ' + JSON.stringify(err)); 1688 } 1689 ``` 1690 1691### setAuthToken<sup>9+</sup> 1692 1693setAuthToken(name: string, authType: string, token: string): Promise<void> 1694 1695Sets an authorization token of the specific authentication type for an application account. This API uses a promise to return the result. 1696 1697**System capability**: SystemCapability.Account.AppAccount 1698 1699**Parameters** 1700 1701| Name | Type | Mandatory | Description | 1702| -------- | ------ | ---- | -------- | 1703| name | string | Yes | Name of the target application account.| 1704| authType | string | Yes | Authentication type. | 1705| token | string | Yes | Authorization token to set.| 1706 1707**Return value** 1708 1709| Type | Description | 1710| ------------------- | --------------------- | 1711| Promise<void> | Promise that returns no value.| 1712 1713**Error codes** 1714 1715| ID| Error Message| 1716| ------- | -------| 1717| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1718| 12300001 | System service exception. | 1719| 12300002 | Invalid name, authType or token. | 1720| 12300003 | Account not found. | 1721| 12400004 | The number of tokens reaches the upper limit. | 1722 1723**Example** 1724 1725 ```ts 1726 import { BusinessError } from '@kit.BasicServicesKit'; 1727 1728 try { 1729 appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { 1730 console.log('setAuthToken successfully'); 1731 }).catch((err: BusinessError) => { 1732 console.log('setAuthToken failed, error: ' + JSON.stringify(err)); 1733 }); 1734 } catch (err) { 1735 console.log('setAuthToken exception: ' + JSON.stringify(err)); 1736 } 1737 ``` 1738 1739### deleteAuthToken<sup>9+</sup> 1740 1741deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 1742 1743Deletes the authorization token of the specified authentication type for an application account. This API uses an asynchronous callback to return the result. 1744 1745**System capability**: SystemCapability.Account.AppAccount 1746 1747**Parameters** 1748 1749| Name | Type | Mandatory | Description | 1750| -------- | ------------------------- | ---- | ------------ | 1751| name | string | Yes | Name of the target application account. | 1752| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 1753| authType | string | Yes | Authentication type. | 1754| token | string | Yes | Authorization token to delete. If the token does not exist, no operation is performed.| 1755| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1756 1757**Error codes** 1758 1759| ID| Error Message| 1760| ------- | ------- | 1761| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1762| 12300001 | System service exception. | 1763| 12300002 | Invalid name, owner, authType or token. | 1764| 12300003 | Account not found. | 1765| 12300107 | AuthType not found. | 1766 1767**Example** 1768 1769 ```ts 1770 import { BusinessError } from '@kit.BasicServicesKit'; 1771 1772 try { 1773 appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', 1774 (err: BusinessError) => { 1775 if (err) { 1776 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1777 } else { 1778 console.log('deleteAuthToken successfully'); 1779 } 1780 }); 1781 } catch (err) { 1782 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1783 } 1784 ``` 1785 1786### deleteAuthToken<sup>9+</sup> 1787 1788deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 1789 1790Deletes the authorization token of the specified authentication type for an application account. This API uses a promise to return the result. 1791 1792**System capability**: SystemCapability.Account.AppAccount 1793 1794**Parameters** 1795 1796| Name | Type | Mandatory | Description | 1797| -------- | ------ | ---- | ------------ | 1798| name | string | Yes | Name of the target application account. | 1799| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 1800| authType | string | Yes | Authentication type. | 1801| token | string | Yes | Authorization token to delete. If the token does not exist, no operation is performed.| 1802 1803**Return value** 1804 1805| Type | Description | 1806| ------------------- | --------------------- | 1807| Promise<void> | Promise that returns no value.| 1808 1809**Error codes** 1810 1811| ID| Error Message| 1812| ------- | ------- | 1813| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1814| 12300001 | System service exception. | 1815| 12300002 | Invalid name, owner, authType or token. | 1816| 12300003 | Account not found. | 1817| 12300107 | AuthType not found. | 1818 1819**Example** 1820 1821 ```ts 1822 import { BusinessError } from '@kit.BasicServicesKit'; 1823 1824 try { 1825 appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { 1826 console.log('deleteAuthToken successfully'); 1827 }).catch((err: BusinessError) => { 1828 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1829 }); 1830 } catch (err) { 1831 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1832 } 1833 ``` 1834 1835### setAuthTokenVisibility<sup>9+</sup> 1836 1837setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 1838 1839Sets the visibility of an authorization token to an application. This API uses an asynchronous callback to return the result. 1840 1841**System capability**: SystemCapability.Account.AppAccount 1842 1843**Parameters** 1844 1845| Name | Type | Mandatory | Description | 1846| ---------- | ------------------------- | ---- | ------------------------- | 1847| name | string | Yes | Name of the target application account. | 1848| authType | string | Yes | Authentication type. | 1849| bundleName | string | Yes | Bundle name of the application. | 1850| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value **true** means the authorization token is visible to the application; the value **false** means the opposite.| 1851| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1852 1853**Error codes** 1854 1855| ID| Error Message| 1856| ------- | -------| 1857| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1858| 12300001 | System service exception. | 1859| 12300002 | Invalid name, authType or bundleName. | 1860| 12300003 | Account not found. | 1861| 12300107 | AuthType not found. | 1862| 12400005 | The size of authorization list reaches the upper limit. | 1863 1864**Example** 1865 1866 ```ts 1867 import { BusinessError } from '@kit.BasicServicesKit'; 1868 1869 try { 1870 appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, 1871 (err: BusinessError) => { 1872 if (err) { 1873 console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1874 } else { 1875 console.log('setAuthTokenVisibility successfully'); 1876 } 1877 }); 1878 } catch (err) { 1879 console.log('setAuthTokenVisibility exception: ' + JSON.stringify(err)); 1880 } 1881 ``` 1882 1883### setAuthTokenVisibility<sup>9+</sup> 1884 1885setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 1886 1887Sets the visibility of an authorization token to an application. This API uses a promise to return the result. 1888 1889**System capability**: SystemCapability.Account.AppAccount 1890 1891**Parameters** 1892 1893| Name | Type | Mandatory | Description | 1894| ---------- | ------------------------- | ---- | ------------------------- | 1895| name | string | Yes | Name of the target application account. | 1896| authType | string | Yes | Authentication type. | 1897| bundleName | string | Yes | Bundle name of the application. | 1898| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value **true** means the authorization token is visible to the application; the value **false** means the opposite.| 1899 1900**Return value** 1901 1902| Type | Description | 1903| ------------------- | --------------------- | 1904| Promise<void> | Promise that returns no value.| 1905 1906**Error codes** 1907 1908| ID| Error Message| 1909| ------- | -------| 1910| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1911| 12300001 | System service exception. | 1912| 12300002 | Invalid name, authType or bundleName. | 1913| 12300003 | Account not found. | 1914| 12300107 | AuthType not found. | 1915| 12400005 | The size of authorization list reaches the upper limit. | 1916 1917**Example** 1918 1919 ```ts 1920 import { BusinessError } from '@kit.BasicServicesKit'; 1921 1922 try { 1923 appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { 1924 console.log('setAuthTokenVisibility successfully'); 1925 }).catch((err: BusinessError) => { 1926 console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1927 }); 1928 } catch (err) { 1929 console.log('setAuthTokenVisibility exception: ' + JSON.stringify(err)); 1930 } 1931 ``` 1932 1933### checkAuthTokenVisibility<sup>9+</sup> 1934 1935checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 1936 1937Checks the visibility of an authorization token of the specified authentication type to an application. This API uses an asynchronous callback to return the result. 1938 1939**System capability**: SystemCapability.Account.AppAccount 1940 1941**Parameters** 1942 1943| Name | Type | Mandatory | Description | 1944| ---------- | ---------------------------- | ---- | ----------- | 1945| name | string | Yes | Name of the target application account. | 1946| authType | string | Yes | Authentication type. | 1947| bundleName | string | Yes | Bundle name of the application.| 1948| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the application) or **false** (the authorization token is not visible to the application). If the operation fails, **err** is an error object. | 1949 1950**Error codes** 1951 1952| ID| Error Message| 1953| ------- | -------| 1954| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1955| 12300001 | System service exception. | 1956| 12300002 | Invalid name, authType or bundleName. | 1957| 12300003 | Account not found. | 1958| 12300107 | AuthType not found. | 1959 1960**Example** 1961 1962 ```ts 1963 import { BusinessError } from '@kit.BasicServicesKit'; 1964 1965 try { 1966 appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', 1967 (err: BusinessError, isVisible: boolean) => { 1968 if (err) { 1969 console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1970 } else { 1971 console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); 1972 } 1973 }); 1974 } catch (err) { 1975 console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err)); 1976 } 1977 ``` 1978 1979### checkAuthTokenVisibility<sup>9+</sup> 1980 1981checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 1982 1983Checks the visibility of an authorization token of the specified authentication type to an application. This API uses a promise to return the result. 1984 1985**System capability**: SystemCapability.Account.AppAccount 1986 1987**Parameters** 1988 1989| Name | Type | Mandatory | Description | 1990| ---------- | ------ | ---- | ------------- | 1991| name | string | Yes | Name of the target application account. | 1992| authType | string | Yes | Authentication type. | 1993| bundleName | string | Yes | Bundle name of the application.| 1994 1995**Return value** 1996 1997| Type | Description | 1998| ---------------------- | --------------------- | 1999| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the application; the value **false** means the opposite.| 2000 2001**Error codes** 2002 2003| ID| Error Message| 2004| ------- | -------| 2005| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2006| 12300001 | System service exception. | 2007| 12300002 | Invalid name, authType or bundleName. | 2008| 12300003 | Account not found. | 2009| 12300107 | AuthType not found. | 2010 2011**Example** 2012 2013 ```ts 2014 import { BusinessError } from '@kit.BasicServicesKit'; 2015 2016 try { 2017 appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then(( 2018 isVisible: boolean) => { 2019 console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); 2020 }).catch((err: BusinessError) => { 2021 console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 2022 }); 2023 } catch (err) { 2024 console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err)); 2025 } 2026 ``` 2027 2028### getAllAuthTokens<sup>9+</sup> 2029 2030getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void 2031 2032Obtains all tokens visible to the invoker for an application account. This API uses an asynchronous callback to return the result. 2033 2034**System capability**: SystemCapability.Account.AppAccount 2035 2036**Parameters** 2037 2038| Name | Type | Mandatory | Description | 2039| -------- | ---------------------------------------- | ---- | ----------- | 2040| name | string | Yes | Name of the target application account. | 2041| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2042| callback | AsyncCallback<Array<[AuthTokenInfo](#authtokeninfo9)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | 2043 2044**Error codes** 2045 2046| ID| Error Message| 2047| ------- | -------| 2048| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2049| 12300001 | System service exception. | 2050| 12300002 | Invalid name or owner. | 2051| 12300003 | Account not found. | 2052 2053**Example** 2054 2055 ```ts 2056 import { BusinessError } from '@kit.BasicServicesKit'; 2057 2058 try { 2059 appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo', 2060 (err: BusinessError, tokenArr: appAccount.AuthTokenInfo[]) => { 2061 if (err) { 2062 console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); 2063 } else { 2064 console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr); 2065 } 2066 }); 2067 } catch (err) { 2068 console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); 2069 } 2070 ``` 2071 2072### getAllAuthTokens<sup>9+</sup> 2073 2074getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>> 2075 2076Obtains all tokens visible to the invoker for an application account. This API uses a promise to return the result. 2077 2078**System capability**: SystemCapability.Account.AppAccount 2079 2080**Parameters** 2081 2082| Name | Type | Mandatory | Description | 2083| ----- | ------ | ---- | ----------- | 2084| name | string | Yes | Name of the target application account. | 2085| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2086 2087**Return value** 2088 2089| Type | Description | 2090| ---------------------------------------- | --------------------- | 2091| Promise<Array<[AuthTokenInfo](#authtokeninfo9)>> | Promise used to return the tokens obtained.| 2092 2093**Error codes** 2094 2095| ID| Error Message| 2096| ------- | -------| 2097| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2098| 12300001 | System service exception. | 2099| 12300002 | Invalid name or owner. | 2100| 12300003 | Account not found. | 2101 2102**Example** 2103 2104 ```ts 2105 import { BusinessError } from '@kit.BasicServicesKit'; 2106 2107 try { 2108 appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then(( 2109 tokenArr: appAccount.AuthTokenInfo[]) => { 2110 console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr)); 2111 }).catch((err: BusinessError) => { 2112 console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); 2113 }); 2114 } catch (err) { 2115 console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); 2116 } 2117 ``` 2118 2119### getAuthList<sup>9+</sup> 2120 2121getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 2122 2123Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses an asynchronous callback to return the result. 2124 2125**System capability**: SystemCapability.Account.AppAccount 2126 2127**Parameters** 2128 2129| Name | Type | Mandatory | Description | 2130| -------- | ---------------------------------------- | ---- | ----------------------- | 2131| name | string | Yes | Name of the target application account. | 2132| authType | string | Yes | Authentication type.| 2133| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object.| 2134 2135**Error codes** 2136 2137| ID| Error Message| 2138| ------- | -------| 2139| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2140| 12300001 | System service exception. | 2141| 12300002 | Invalid name or authType. | 2142| 12300003 | Account not found. | 2143| 12300107 | AuthType not found. | 2144 2145**Example** 2146 2147 ```ts 2148 import { BusinessError } from '@kit.BasicServicesKit'; 2149 2150 try { 2151 appAccountManager.getAuthList('LiSi', 'getSocialData', (err: BusinessError, authList: string[]) => { 2152 if (err) { 2153 console.log('getAuthList failed, error: ' + JSON.stringify(err)); 2154 } else { 2155 console.log('getAuthList successfully, authList: ' + authList); 2156 } 2157 }); 2158 } catch (err) { 2159 console.log('getAuthList exception: ' + JSON.stringify(err)); 2160 } 2161 ``` 2162 2163### getAuthList<sup>9+</sup> 2164 2165getAuthList(name: string, authType: string): Promise<Array<string>> 2166 2167Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses a promise to return the result. 2168 2169**System capability**: SystemCapability.Account.AppAccount 2170 2171**Parameters** 2172 2173| Name | Type | Mandatory | Description | 2174| -------- | ------ | ---- | ------------------------------ | 2175| name | string | Yes | Name of the target application account. | 2176| authType | string | Yes | Authentication type.| 2177 2178**Return value** 2179 2180| Type | Description | 2181| ---------------------------------- | --------------------- | 2182| Promise<Array<string>> | Promise used to return a list of authorized bundles.| 2183 2184**Error codes** 2185 2186| ID| Error Message| 2187| ------- | -------| 2188| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2189| 12300001 | System service exception. | 2190| 12300002 | Invalid name or authType. | 2191| 12300003 | Account not found. | 2192| 12300107 | AuthType not found. | 2193 2194**Example** 2195 2196 ```ts 2197 import { BusinessError } from '@kit.BasicServicesKit'; 2198 2199 try { 2200 appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList: string[]) => { 2201 console.log('getAuthList successfully, authList: ' + authList); 2202 }).catch((err: BusinessError) => { 2203 console.log('getAuthList failed, error: ' + JSON.stringify(err)); 2204 }); 2205 } catch (err) { 2206 console.log('getAuthList exception: ' + JSON.stringify(err)); 2207 } 2208 ``` 2209 2210### getAuthCallback<sup>9+</sup> 2211 2212getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void 2213 2214Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. 2215 2216**System capability**: SystemCapability.Account.AppAccount 2217 2218**Parameters** 2219 2220| Name | Type | Mandatory | Description | 2221| --------- | ---------------------------------------- | ---- | -------- | 2222| sessionId | string | Yes | ID of the authentication session.| 2223| callback | AsyncCallback<[AuthCallback](#authcallback9)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback object obtained. Otherwise, **err** is an error object.| 2224 2225**Error codes** 2226 2227| ID| Error Message| 2228| ------- | ------- | 2229| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2230| 12300001 | System service exception. | 2231| 12300002 | Invalid sessionId. | 2232| 12300108 | Session not found. | 2233 2234**Example** 2235 2236 ```ts 2237 import { BusinessError } from '@kit.BasicServicesKit'; 2238 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 2239 2240 export default class EntryAbility extends UIAbility { 2241 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 2242 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 2243 try { 2244 appAccountManager.getAuthCallback(sessionId, (err: BusinessError, callback: appAccount.AuthCallback) => { 2245 if (err != null) { 2246 console.log('getAuthCallback err: ' + JSON.stringify(err)); 2247 return; 2248 } 2249 let result: appAccount.AuthResult = { 2250 account: { 2251 name: 'Lisi', 2252 owner: 'com.example.accountjsdemo', 2253 }, 2254 tokenInfo: { 2255 token: 'xxxxxx', 2256 authType: 'getSocialData' 2257 } 2258 }; 2259 callback.onResult(0, result); 2260 }); 2261 } catch (err) { 2262 console.log('getAuthCallback exception: ' + JSON.stringify(err)); 2263 } 2264 } 2265 } 2266 ``` 2267 2268### getAuthCallback<sup>9+</sup> 2269 2270getAuthCallback(sessionId: string): Promise<AuthCallback> 2271 2272Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. 2273 2274**System capability**: SystemCapability.Account.AppAccount 2275 2276**Parameters** 2277 2278| Name | Type | Mandatory | Description | 2279| --------- | ------ | ---- | -------- | 2280| sessionId | string | Yes | ID of the authentication session.| 2281 2282**Return value** 2283 2284| Type | Description | 2285| ------------------------------------ | --------------------- | 2286| Promise<[AuthCallback](#authcallback9)> | Promise used to return the authenticator callback obtained.| 2287 2288**Error codes** 2289 2290| ID| Error Message| 2291| ------- | ------- | 2292| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2293| 12300001 | System service exception. | 2294| 12300002 | Invalid sessionId. | 2295| 12300108 | Session not found. | 2296 2297**Example** 2298 2299 ```ts 2300 import { BusinessError } from '@kit.BasicServicesKit'; 2301 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 2302 2303 export default class EntryAbility extends UIAbility { 2304 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 2305 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 2306 try { 2307 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 2308 let result: appAccount.AuthResult = { 2309 account: { 2310 name: 'Lisi', 2311 owner: 'com.example.accountjsdemo', 2312 }, 2313 tokenInfo: { 2314 token: 'xxxxxx', 2315 authType: 'getSocialData' 2316 } 2317 }; 2318 callback.onResult(0, result); 2319 }).catch((err: BusinessError) => { 2320 console.log('getAuthCallback err: ' + JSON.stringify(err)); 2321 }); 2322 } catch (err) { 2323 console.log('getAuthCallback exception: ' + JSON.stringify(err)); 2324 } 2325 } 2326 } 2327 ``` 2328 2329### queryAuthenticatorInfo<sup>9+</sup> 2330 2331queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 2332 2333Obtains the authenticator information of an application. This API uses an asynchronous callback to return the result. 2334 2335**System capability**: SystemCapability.Account.AppAccount 2336 2337**Parameters** 2338 2339| Name | Type | Mandatory | Description | 2340| -------- | -------------------------------------- | ---- | ----------- | 2341| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2342| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | 2343 2344**Error codes** 2345 2346| ID| Error Message| 2347| ------- | -------| 2348| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2349| 12300001 | System service exception. | 2350| 12300002 | Invalid owner. | 2351| 12300113 | Authenticator service not found. | 2352 2353**Example** 2354 2355 ```ts 2356 import { BusinessError } from '@kit.BasicServicesKit'; 2357 2358 try { 2359 appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo', 2360 (err: BusinessError, info: appAccount.AuthenticatorInfo) => { 2361 if (err) { 2362 console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); 2363 } else { 2364 console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); 2365 } 2366 }); 2367 } catch (err) { 2368 console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); 2369 } 2370 ``` 2371 2372### queryAuthenticatorInfo<sup>9+</sup> 2373 2374queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 2375 2376Obtains the authenticator information of an application. This API uses a promise to return the result. 2377 2378**System capability**: SystemCapability.Account.AppAccount 2379 2380**Parameters** 2381 2382| Name | Type | Mandatory | Description | 2383| ----- | ------ | ---- | ----------- | 2384| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2385 2386**Return value** 2387 2388| Type | Description | 2389| -------------------------------- | --------------------- | 2390| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| 2391 2392**Error codes** 2393 2394| ID| Error Message| 2395| ------- | -------| 2396| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2397| 12300001 | System service exception. | 2398| 12300002 | Invalid owner. | 2399| 12300113 | Authenticator service not found. | 2400 2401**Example** 2402 2403 ```ts 2404 import { BusinessError } from '@kit.BasicServicesKit'; 2405 2406 try { 2407 appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then(( 2408 info: appAccount.AuthenticatorInfo) => { 2409 console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); 2410 }).catch((err: BusinessError) => { 2411 console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); 2412 }); 2413 } catch (err) { 2414 console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); 2415 } 2416 ``` 2417 2418### checkAccountLabels<sup>9+</sup> 2419 2420checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void 2421 2422Checks whether an application account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target application. 2423 2424**System capability**: SystemCapability.Account.AppAccount 2425 2426**Parameters** 2427 2428| Name | Type | Mandatory | Description | 2429| -------------- | ------------------------- | ----- | --------------- | 2430| name | string | Yes | Name of the target application account. | 2431| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2432| labels | Array<string> | Yes | Labels to check. | 2433| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** can be **true** or **false**. The value **true** means the application account has the labels; the value **false** means the opposite. If the operation fails, **err** is an error object. | 2434 2435**Error codes** 2436 2437| ID| Error Message| 2438| ------- | ------- | 2439| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2440| 12300001 | System service exception. | 2441| 12300002 | Invalid name, owner or labels. | 2442| 12300003 | Account not found. | 2443| 12300010 | Account service busy. | 2444| 12300113 | Authenticator service not found. | 2445| 12300114 | Authenticator service exception. | 2446 2447**Example** 2448 2449 ```ts 2450 import { BusinessError } from '@kit.BasicServicesKit'; 2451 2452 let labels = ['student']; 2453 try { 2454 appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels, 2455 (err: BusinessError, hasAllLabels: boolean) => { 2456 if (err) { 2457 console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); 2458 } else { 2459 console.log('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels); 2460 } 2461 }); 2462 } catch (err) { 2463 console.log('checkAccountLabels exception: ' + JSON.stringify(err)); 2464 } 2465 ``` 2466 2467### checkAccountLabels<sup>9+</sup> 2468 2469checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean> 2470 2471Checks whether an application account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target application. 2472 2473**System capability**: SystemCapability.Account.AppAccount 2474 2475**Parameters** 2476 2477| Name | Type | Mandatory | Description | 2478| -------------- | ------------------------- | ----- | --------------- | 2479| name | string | Yes | Name of the target application account. | 2480| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 2481| labels | Array<string> | Yes | Labels to check. | 2482 2483**Return value** 2484 2485| Type | Description | 2486| ------------------- | -------------------------------- | 2487| Promise<boolean> | Promise used to return the result. The value **true** means the application account has the labels; the value **false** means the opposite.| 2488 2489**Error codes** 2490 2491| ID| Error Message| 2492| ------- | ------- | 2493| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2494| 12300001 | System service exception. | 2495| 12300002 | Invalid name, owner or labels. | 2496| 12300003 | Account not found. | 2497| 12300010 | Account service busy. | 2498| 12300113 | Authenticator service not found. | 2499| 12300114 | Authenticator service exception. | 2500 2501**Example** 2502 2503 ```ts 2504 import { BusinessError } from '@kit.BasicServicesKit'; 2505 2506 let labels = ['student']; 2507 try { 2508 appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then(( 2509 hasAllLabels: boolean) => { 2510 console.log('checkAccountLabels successfully: ' + hasAllLabels); 2511 }).catch((err: BusinessError) => { 2512 console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); 2513 }); 2514 } catch (err) { 2515 console.log('checkAccountLabels exception: ' + JSON.stringify(err)); 2516 } 2517 ``` 2518 2519### deleteCredential<sup>9+</sup> 2520 2521deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void 2522 2523Deletes the credential of the specified type from an application account. This API uses an asynchronous callback to return the result. 2524 2525**System capability**: SystemCapability.Account.AppAccount 2526 2527**Parameters** 2528 2529| Name | Type | Mandatory | Description | 2530| -------------- | ------------------------- | ----- | -------------- | 2531| name | string | Yes | Name of the target application account.| 2532| credentialType | string | Yes | Type of the credential to delete. | 2533| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2534 2535**Error codes** 2536 2537| ID| Error Message| 2538| ------- | ------- | 2539| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2540| 12300001 | System service exception. | 2541| 12300002 | Invalid name or credentialType. | 2542| 12300003 | Account not found. | 2543| 12300102 | Credential not found. | 2544 2545**Example** 2546 2547 ```ts 2548 import { BusinessError } from '@kit.BasicServicesKit'; 2549 2550 try { 2551 appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err: BusinessError) => { 2552 if (err) { 2553 console.log('deleteCredential failed, error: ' + JSON.stringify(err)); 2554 } else { 2555 console.log('deleteCredential successfully'); 2556 } 2557 }); 2558 } catch (err) { 2559 console.log('deleteCredential exception: ' + JSON.stringify(err)); 2560 } 2561 ``` 2562 2563### deleteCredential<sup>9+</sup> 2564 2565deleteCredential(name: string, credentialType: string): Promise<void> 2566 2567Deletes the credential of the specified type from an application account. This API uses a promise to return the result. 2568 2569**System capability**: SystemCapability.Account.AppAccount 2570 2571**Parameters** 2572 2573| Name | Type | Mandatory | Description | 2574| -------------- | ------ | ----- | --------------- | 2575| name | string | Yes | Name of the target application account.| 2576| credentialType | string | Yes | Type of the credential to delete. | 2577 2578**Return value** 2579 2580| Type | Description | 2581| ------------------- | -------------------------------- | 2582| Promise<void> | Promise that returns no value.| 2583 2584**Error codes** 2585 2586| ID| Error Message| 2587| ------- | ------- | 2588| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2589| 12300001 | System service exception. | 2590| 12300002 | Invalid name or credentialType. | 2591| 12300003 | Account not found. | 2592| 12300102 | Credential not found. | 2593 2594**Example** 2595 2596 ```ts 2597 import { BusinessError } from '@kit.BasicServicesKit'; 2598 2599 try { 2600 appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => { 2601 console.log('deleteCredential successfully'); 2602 }).catch((err: BusinessError) => { 2603 console.log('deleteCredential failed, error: ' + JSON.stringify(err)); 2604 }); 2605 } catch (err) { 2606 console.log('deleteCredential exception: ' + JSON.stringify(err)); 2607 } 2608 ``` 2609 2610### selectAccountsByOptions<sup>9+</sup> 2611 2612selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void 2613 2614Selects the accounts that can be accessed by the invoker based on the options. This API uses an asynchronous callback to return the result. If the options contain label constraints, the authenticator of the target application provides the capability of checking the labels. 2615 2616**System capability**: SystemCapability.Account.AppAccount 2617 2618**Parameters** 2619 2620| Name | Type | Mandatory | Description | 2621| -------------- | ----------------------------------- | ----- | --------------- | 2622| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | 2623| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of accounts selected. Otherwise, **err** is an error object. | 2624 2625**Error codes** 2626 2627| ID| Error Message| 2628| ------- | ------- | 2629| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2630| 12300001 | System service exception. | 2631| 12300002 | Invalid options. | 2632| 12300010 | Account service busy. | 2633| 12300114 | Authenticator service exception. | 2634 2635**Example** 2636 2637 ```ts 2638 import { BusinessError } from '@kit.BasicServicesKit'; 2639 2640 let options: appAccount.SelectAccountsOptions = { 2641 allowedOwners: [ 'com.example.accountjsdemo' ], 2642 requiredLabels: [ 'student' ] 2643 }; 2644 try { 2645 appAccountManager.selectAccountsByOptions(options, 2646 (err: BusinessError, accountArr: appAccount.AppAccountInfo[]) => { 2647 if (err) { 2648 console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); 2649 } else { 2650 console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); 2651 } 2652 }); 2653 } catch (err) { 2654 console.log('selectAccountsByOptions exception: ' + JSON.stringify(err)); 2655 } 2656 ``` 2657 2658### selectAccountsByOptions<sup>9+</sup> 2659 2660selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> 2661 2662Selects the accounts that can be accessed by the invoker based on the options. This API uses a promise to return the result. If the options contain label constraints, the authenticator of the target application provides the capability of checking the labels. 2663 2664**System capability**: SystemCapability.Account.AppAccount 2665 2666**Parameters** 2667 2668| Name | Type | Mandatory | Description | 2669| -------------- | ------------------------- | ----- | --------------- | 2670| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | 2671 2672**Return value** 2673 2674| Type | Description | 2675| ------------------- | -------------------------------- | 2676| Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the accounts selected.| 2677 2678**Error codes** 2679 2680| ID| Error Message| 2681| ------- | ------- | 2682| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2683| 12300001 | System service exception. | 2684| 12300002 | Invalid options. | 2685| 12300010 | Account service busy. | 2686| 12300114 | Authenticator service exception. | 2687 2688**Example** 2689 2690 ```ts 2691 import { BusinessError } from '@kit.BasicServicesKit'; 2692 2693 let options: appAccount.SelectAccountsOptions = { 2694 allowedOwners: ['com.example.accountjsdemo'] 2695 }; 2696 try { 2697 appAccountManager.selectAccountsByOptions(options).then((accountArr: appAccount.AppAccountInfo[]) => { 2698 console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); 2699 }).catch((err: BusinessError) => { 2700 console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); 2701 }); 2702 } catch (err) { 2703 console.log('selectAccountsByOptions exception: ' + JSON.stringify(err)); 2704 } 2705 ``` 2706 2707### verifyCredential<sup>9+</sup> 2708 2709verifyCredential(name: string, owner: string, callback: AuthCallback): void 2710 2711Verifies the credential of an application account. This API uses an asynchronous callback to return the result. 2712 2713**System capability**: SystemCapability.Account.AppAccount 2714 2715**Parameters** 2716 2717| Name | Type | Mandatory | Description | 2718| -------- | --------------------- | ----- | ----------------------- | 2719| name | string | Yes | Name of the target application account. | 2720| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 2721| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result.| 2722 2723**Error codes** 2724 2725| ID| Error Message| 2726| ------- | -------| 2727| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2728| 12300001 | System service exception. | 2729| 12300002 | Invalid name or owner. | 2730| 12300003 | Account not found. | 2731| 12300010 | Account service busy. | 2732| 12300113 | Authenticator service not found. | 2733| 12300114 | Authenticator service exception. | 2734 2735**Example** 2736 2737 ```ts 2738 import { Want } from '@kit.AbilityKit'; 2739 2740 try { 2741 appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', { 2742 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2743 console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); 2744 console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); 2745 }, 2746 onRequestRedirected: (request: Want) => { 2747 console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); 2748 } 2749 }); 2750 } catch (err) { 2751 console.log('verifyCredential err: ' + JSON.stringify(err)); 2752 } 2753 ``` 2754 2755### verifyCredential<sup>9+</sup> 2756 2757verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void 2758 2759Verifies the user credential. This API uses an asynchronous callback to return the result. 2760 2761**System capability**: SystemCapability.Account.AppAccount 2762 2763**Parameters** 2764 2765| Name | Type | Mandatory | Description | 2766| -------- | ----------------------- | ----- | ----------------------- | 2767| name | string | Yes | Name of the target application account. | 2768| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 2769| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for verifying the user credential. | 2770| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result.| 2771 2772**Error codes** 2773 2774| ID| Error Message| 2775| ------- | -------| 2776| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2777| 12300001 | System service exception. | 2778| 12300002 | Invalid name, owner or options. | 2779| 12300003 | Account not found. | 2780| 12300010 | Account service busy. | 2781| 12300113 | Authenticator service not found. | 2782| 12300114 | Authenticator service exception. | 2783 2784**Example** 2785 2786 ```ts 2787 import { Want } from '@kit.AbilityKit'; 2788 2789 let options: appAccount.VerifyCredentialOptions = { 2790 credentialType: 'pin', 2791 credential: '123456' 2792 }; 2793 try { 2794 appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, { 2795 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2796 console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); 2797 console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); 2798 }, 2799 onRequestRedirected: (request: Want) => { 2800 console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); 2801 } 2802 }); 2803 } catch (err) { 2804 console.log('verifyCredential err: ' + JSON.stringify(err)); 2805 } 2806 ``` 2807 2808### setAuthenticatorProperties<sup>9+</sup> 2809 2810setAuthenticatorProperties(owner: string, callback: AuthCallback): void 2811 2812Sets the authenticator attributes of an application. This API uses an asynchronous callback to return the result. 2813 2814**System capability**: SystemCapability.Account.AppAccount 2815 2816**Parameters** 2817 2818| Name | Type | Mandatory | Description | 2819| -------- | --------------------- | ----- | ----------------------- | 2820| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the application. | 2821| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result.| 2822 2823**Error codes** 2824 2825| ID| Error Message| 2826| ------- | ------- | 2827| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2828| 12300001 | System service exception. | 2829| 12300002 | Invalid owner. | 2830| 12300010 | Account service busy. | 2831| 12300113 | Authenticator service not found. | 2832| 12300114 | Authenticator service exception. | 2833 2834**Example** 2835 2836 ```ts 2837 import { Want } from '@kit.AbilityKit'; 2838 2839 try { 2840 appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', { 2841 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2842 console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); 2843 console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); 2844 }, 2845 onRequestRedirected: (request: Want) => { 2846 console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); 2847 } 2848 }); 2849 } catch (err) { 2850 console.log('setAuthenticatorProperties err: ' + JSON.stringify(err)); 2851 } 2852 ``` 2853 2854### setAuthenticatorProperties<sup>9+</sup> 2855 2856setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void 2857 2858Sets the authenticator properties. This API uses an asynchronous callback to return the result. 2859 2860**System capability**: SystemCapability.Account.AppAccount 2861 2862**Parameters** 2863 2864| Name | Type | Mandatory | Description | 2865| -------- | --------------------- | ----- | ----------------------- | 2866| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the application. | 2867| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 2868| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 2869 2870**Error codes** 2871 2872| ID| Error Message| 2873| ------- | ------- | 2874| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2875| 12300001 | System service exception. | 2876| 12300002 | Invalid owner or options. | 2877| 12300010 | Account service busy. | 2878| 12300113 | Authenticator service not found. | 2879| 12300114 | Authenticator service exception. | 2880 2881**Example** 2882 2883 ```ts 2884 import { Want } from '@kit.AbilityKit'; 2885 2886 let options: appAccount.SetPropertiesOptions = { 2887 properties: {prop1: 'value1'} 2888 }; 2889 try { 2890 appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, { 2891 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2892 console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); 2893 console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); 2894 }, 2895 onRequestRedirected: (request: Want) => { 2896 console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); 2897 } 2898 }); 2899 } catch (err) { 2900 console.log('setAuthenticatorProperties err: ' + JSON.stringify(err)); 2901 } 2902 2903 ``` 2904 2905### addAccount<sup>(deprecated)</sup> 2906 2907addAccount(name: string, callback: AsyncCallback<void>): void 2908 2909Adds an application account with the given name. This API uses an asynchronous callback to return the result. 2910 2911> **NOTE** 2912> 2913>This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9) instead. 2914 2915 2916**System capability**: SystemCapability.Account.AppAccount 2917 2918**Parameters** 2919 2920| Name | Type | Mandatory | Description | 2921| -------- | ------------------------- | ---- | -------------------- | 2922| name | string | Yes | Name of the target application account. | 2923| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2924 2925**Example** 2926 2927 ```ts 2928 import { BusinessError } from '@kit.BasicServicesKit'; 2929 2930 appAccountManager.addAccount('WangWu', (err: BusinessError) => { 2931 console.log('addAccount err: ' + JSON.stringify(err)); 2932 }); 2933 ``` 2934 2935### addAccount<sup>(deprecated)</sup> 2936 2937addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void 2938 2939Adds an application account name and additional information. This API uses an asynchronous callback to return the result. 2940 2941> **NOTE** 2942> This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9-1) instead. 2943 2944**System capability**: SystemCapability.Account.AppAccount 2945 2946**Parameters** 2947 2948| Name | Type | Mandatory | Description | 2949| --------- | ------------------------- | ---- | ---------------------------------------- | 2950| name | string | Yes | Name of the target application account. | 2951| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token.| 2952| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 2953 2954**Example** 2955 2956 ```ts 2957 import { BusinessError } from '@kit.BasicServicesKit'; 2958 2959 appAccountManager.addAccount('LiSi', 'token101', (err: BusinessError) => { 2960 console.log('addAccount err: ' + JSON.stringify(err)); 2961 }); 2962 ``` 2963 2964### addAccount<sup>(deprecated)</sup> 2965 2966addAccount(name: string, extraInfo?: string): Promise<void> 2967 2968Adds an application account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. 2969 2970> **NOTE** 2971> This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9-2) instead. 2972 2973**System capability**: SystemCapability.Account.AppAccount 2974 2975**Parameters** 2976 2977| Name | Type | Mandatory | Description | 2978| --------- | ------ | ---- | ---------------------------------------- | 2979| name | string | Yes | Name of the target application account. | 2980| extraInfo | string | No | Additional information (information that can be converted to the string type). <br>The additional information cannot be sensitive information (such as the password and token) of the application account.<br>By default, no value is passed, which means no additional information needs to be added for the account.| 2981 2982**Return value** 2983 2984| Type | Description | 2985| ------------------- | --------------------- | 2986| Promise<void> | Promise that returns no value.| 2987 2988**Example** 2989 2990 ```ts 2991 import { BusinessError } from '@kit.BasicServicesKit'; 2992 2993 appAccountManager.addAccount('LiSi', 'token101').then(()=> { 2994 console.log('addAccount Success'); 2995 }).catch((err: BusinessError) => { 2996 console.log('addAccount err: ' + JSON.stringify(err)); 2997 }); 2998 ``` 2999 3000### addAccountImplicitly<sup>(deprecated)</sup> 3001 3002addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 3003 3004Adds an application account implicitly based on the specified owner. This API uses an asynchronous callback to return the result. 3005 3006> **NOTE** 3007> 3008> This API is supported since API version 8 and deprecated since API version 9. Use [createAccountImplicitly](#createaccountimplicitly9) instead. 3009 3010**System capability**: SystemCapability.Account.AppAccount 3011 3012**Parameters** 3013 3014| Name | Type | Mandatory | Description | 3015| -------- | --------------------- | ---- | ----------------------- | 3016| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 3017| authType | string | Yes | Authentication type. The authentication type is customized. | 3018| options | {[key: string]: any} | Yes | Authentication options, which can be set as required.| 3019| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the result. | 3020 3021**Example** 3022 3023 ```ts 3024 import { BusinessError } from '@kit.BasicServicesKit'; 3025 import { Want, common } from '@kit.AbilityKit'; 3026 3027 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 3028 3029 function onResultCallback(code: number, result: Record<string, Object>): void { 3030 console.log('resultCode: ' + code); 3031 console.log('result: ' + JSON.stringify(result)); 3032 } 3033 3034 function onRequestRedirectedCallback(request: Want): void { 3035 let wantInfo: Want = { 3036 deviceId: '', 3037 bundleName: 'com.example.accountjsdemo', 3038 action: 'ohos.want.action.viewData', 3039 entities: ['entity.system.default'], 3040 } 3041 context.startAbility(wantInfo).then(() => { 3042 console.log('startAbility successfully'); 3043 }).catch((err: BusinessError) => { 3044 console.log('startAbility err: ' + JSON.stringify(err)); 3045 }) 3046 } 3047 3048 appAccountManager.addAccountImplicitly('com.example.accountjsdemo', 'getSocialData', {}, { 3049 onResult: onResultCallback, 3050 onRequestRedirected: onRequestRedirectedCallback 3051 }); 3052 ``` 3053 3054### deleteAccount<sup>(deprecated)</sup> 3055 3056deleteAccount(name: string, callback: AsyncCallback<void>): void 3057 3058Deletes an application account. This API uses an asynchronous callback to return the result. 3059 3060> **NOTE** 3061> 3062> This API is supported since API version 7 and deprecated since API version 9. Use [removeAccount](#removeaccount9) instead. 3063 3064**System capability**: SystemCapability.Account.AppAccount 3065 3066**Parameters** 3067 3068| Name | Type | Mandatory | Description | 3069| -------- | ------------------------- | ---- | ---------------- | 3070| name | string | Yes | Name of the target application account. | 3071| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3072 3073**Example** 3074 3075 ```ts 3076 import { BusinessError } from '@kit.BasicServicesKit'; 3077 3078 appAccountManager.deleteAccount('ZhaoLiu', (err: BusinessError) => { 3079 console.log('deleteAccount err: ' + JSON.stringify(err)); 3080 }); 3081 ``` 3082 3083### deleteAccount<sup>(deprecated)</sup> 3084 3085deleteAccount(name: string): Promise<void> 3086 3087Deletes an application account. This API uses a promise to return the result. 3088 3089> **NOTE** 3090> 3091> This API is supported since API version 7 and deprecated since API version 9. Use [removeAccount](#removeaccount9) instead. 3092 3093**System capability**: SystemCapability.Account.AppAccount 3094 3095**Parameters** 3096 3097| Name | Type | Mandatory | Description | 3098| ---- | ------ | ---- | ----------- | 3099| name | string | Yes | Name of the target application account.| 3100 3101**Return value** 3102 3103| Type | Description | 3104| :------------------ | :-------------------- | 3105| Promise<void> | Promise that returns no value.| 3106 3107**Example** 3108 3109 ```ts 3110 import { BusinessError } from '@kit.BasicServicesKit'; 3111 3112 appAccountManager.deleteAccount('ZhaoLiu').then(() => { 3113 console.log('deleteAccount Success'); 3114 }).catch((err: BusinessError) => { 3115 console.log('deleteAccount err: ' + JSON.stringify(err)); 3116 }); 3117 ``` 3118### disableAppAccess<sup>(deprecated)</sup> 3119 3120disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 3121 3122Disables an application account from accessing an application. This API uses an asynchronous callback to return the result. 3123 3124> **NOTE** 3125> 3126> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9) instead. 3127 3128**System capability**: SystemCapability.Account.AppAccount 3129 3130**Parameters** 3131 3132| Name | Type | Mandatory | Description | 3133| ---------- | ------------------------- | ---- | --------------------------------- | 3134| name | string | Yes | Name of the target application account. | 3135| bundleName | string | Yes | Bundle name of the application. | 3136| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3137 3138**Example** 3139 3140 ```ts 3141 import { BusinessError } from '@kit.BasicServicesKit'; 3142 3143 appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => { 3144 console.log('disableAppAccess err: ' + JSON.stringify(err)); 3145 }); 3146 ``` 3147 3148### disableAppAccess<sup>(deprecated)</sup> 3149 3150disableAppAccess(name: string, bundleName: string): Promise<void> 3151 3152Disables an application account from accessing an application. This API uses a promise to return the result. 3153 3154> **NOTE** 3155> 3156> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9-1) instead. 3157 3158**System capability**: SystemCapability.Account.AppAccount 3159 3160**Parameters** 3161 3162| Name | Type | Mandatory | Description | 3163| ---------- | ------ | ---- | ---------------- | 3164| name | string | Yes | Name of the target application account.| 3165| bundleName | string | Yes | Bundle name of the application. | 3166 3167**Return value** 3168 3169| Type | Description | 3170| :------------------ | :-------------------- | 3171| Promise<void> | Promise that returns no value.| 3172 3173**Example** 3174 3175 ```ts 3176 import { BusinessError } from '@kit.BasicServicesKit'; 3177 3178 appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { 3179 console.log('disableAppAccess Success'); 3180 }).catch((err: BusinessError) => { 3181 console.log('disableAppAccess err: ' + JSON.stringify(err)); 3182 }); 3183 ``` 3184 3185### enableAppAccess<sup>(deprecated)</sup> 3186 3187enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 3188 3189Enables an application account to access an application. This API uses an asynchronous callback to return the result. 3190 3191> **NOTE** 3192> 3193> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9) instead. 3194 3195**System capability**: SystemCapability.Account.AppAccount 3196 3197**Parameters** 3198 3199| Name | Type | Mandatory | Description | 3200| ---------- | ------------------------- | ---- | --------------------------------- | 3201| name | string | Yes | Name of the target application account. | 3202| bundleName | string | Yes | Bundle name of the application. | 3203| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3204 3205**Example** 3206 3207 ```ts 3208 import { BusinessError } from '@kit.BasicServicesKit'; 3209 3210 appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => { 3211 console.log('enableAppAccess: ' + JSON.stringify(err)); 3212 }); 3213 ``` 3214 3215### enableAppAccess<sup>(deprecated)</sup> 3216 3217enableAppAccess(name: string, bundleName: string): Promise<void> 3218 3219Enables an application account to access an application. This API uses a promise to return the result. 3220 3221> **NOTE** 3222> 3223> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9-1) instead. 3224 3225**System capability**: SystemCapability.Account.AppAccount 3226 3227**Parameters** 3228 3229| Name | Type | Mandatory | Description | 3230| ---------- | ------ | ---- | --------- | 3231| name | string | Yes | Name of the target application account. | 3232| bundleName | string | Yes | Bundle name of the application.| 3233 3234**Return value** 3235 3236| Type | Description | 3237| :------------------ | :-------------------- | 3238| Promise<void> | Promise that returns no value.| 3239 3240**Example** 3241 3242 ```ts 3243 import { BusinessError } from '@kit.BasicServicesKit'; 3244 3245 appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { 3246 console.log('enableAppAccess Success'); 3247 }).catch((err: BusinessError) => { 3248 console.log('enableAppAccess err: ' + JSON.stringify(err)); 3249 }); 3250 ``` 3251 3252### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3253 3254checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void 3255 3256Checks whether data synchronization is enabled for an application account. This API uses an asynchronous callback to return the result. 3257 3258> **NOTE** 3259> 3260> This API is supported since API version 7 and deprecated since API version 9. Use [checkDataSyncEnabled](#checkdatasyncenabled9) instead. 3261 3262**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3263 3264**System capability**: SystemCapability.Account.AppAccount 3265 3266**Parameters** 3267 3268| Name | Type | Mandatory | Description | 3269| -------- | ---------------------------- | ---- | --------------------- | 3270| name | string | Yes | Name of the target application account. | 3271| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means data synchronization is enabled for the application account; the value **false** means the opposite.| 3272 3273**Example** 3274 3275 ```ts 3276 import { BusinessError } from '@kit.BasicServicesKit'; 3277 3278 appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err: BusinessError, result: boolean) => { 3279 console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); 3280 console.log('checkAppAccountSyncEnable result: ' + result); 3281 }); 3282 ``` 3283 3284### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3285 3286checkAppAccountSyncEnable(name: string): Promise<boolean> 3287 3288Checks whether data synchronization is enabled for an application account. This API uses a promise to return the result. 3289 3290> **NOTE** 3291> 3292> This API is supported since API version 7 and deprecated since API version 9. Use [checkDataSyncEnabled](#checkdatasyncenabled9-1) instead. 3293 3294**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3295 3296**System capability**: SystemCapability.Account.AppAccount 3297 3298**Parameters** 3299 3300| Name | Type | Mandatory | Description | 3301| ---- | ------ | ---- | ------- | 3302| name | string | Yes | Name of the target application account.| 3303 3304**Return value** 3305 3306| Type | Description | 3307| ---------------------- | --------------------- | 3308| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the application account; the value **false** means the opposite.| 3309 3310**Example** 3311 3312 ```ts 3313 import { BusinessError } from '@kit.BasicServicesKit'; 3314 3315 appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data: boolean) => { 3316 console.log('checkAppAccountSyncEnable, result: ' + data); 3317 }).catch((err: BusinessError) => { 3318 console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); 3319 }); 3320 ``` 3321 3322### setAccountCredential<sup>(deprecated)</sup> 3323 3324setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void 3325 3326Sets a credential for an application account. This API uses an asynchronous callback to return the result. 3327 3328> **NOTE** 3329> 3330> This API is supported since API version 7 and deprecated since API version 9. Use [setCredential](#setcredential9) instead. 3331 3332**System capability**: SystemCapability.Account.AppAccount 3333 3334**Parameters** 3335 3336| Name | Type | Mandatory | Description | 3337| -------------- | ------------------------- | ---- | ------------- | 3338| name | string | Yes | Name of the target application account. | 3339| credentialType | string | Yes | Type of the credential to set. | 3340| credential | string | Yes | Credential value. | 3341| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3342 3343**Example** 3344 3345 ```ts 3346 import { BusinessError } from '@kit.BasicServicesKit'; 3347 3348 appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err: BusinessError) => { 3349 console.log('setAccountCredential err: ' + JSON.stringify(err)); 3350 }); 3351 ``` 3352 3353### setAccountCredential<sup>(deprecated)</sup> 3354 3355setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> 3356 3357Sets a credential for an application account. This API uses a promise to return the result. 3358 3359> **NOTE** 3360> 3361> This API is supported since API version 7 and deprecated since API version 9. Use [setCredential](#setcredential9-1) instead. 3362 3363**System capability**: SystemCapability.Account.AppAccount 3364 3365**Parameters** 3366 3367| Name | Type | Mandatory | Description | 3368| -------------- | ------ | ---- | ---------- | 3369| name | string | Yes | Name of the target application account. | 3370| credentialType | string | Yes | Type of the credential to set.| 3371| credential | string | Yes | Credential value.| 3372 3373**Return value** 3374 3375| Type | Description | 3376| :------------------ | :-------------------- | 3377| Promise<void> | Promise that returns no value.| 3378 3379**Example** 3380 3381 ```ts 3382 import { BusinessError } from '@kit.BasicServicesKit'; 3383 3384 appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => { 3385 console.log('setAccountCredential Success'); 3386 }).catch((err: BusinessError) => { 3387 console.log('setAccountCredential err: ' + JSON.stringify(err)); 3388 }); 3389 ``` 3390 3391### setAccountExtraInfo<sup>(deprecated)</sup> 3392 3393setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void 3394 3395Sets additional information for an application account. This API uses an asynchronous callback to return the result. 3396 3397> **NOTE** 3398> 3399> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9) instead. 3400 3401 3402**System capability**: SystemCapability.Account.AppAccount 3403 3404**Parameters** 3405 3406| Name | Type | Mandatory | Description | 3407| --------- | ------------------------- | ---- | --------------- | 3408| name | string | Yes | Name of the target application account. | 3409| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token. | 3410| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3411 3412**Example** 3413 3414 ```ts 3415 import { BusinessError } from '@kit.BasicServicesKit'; 3416 3417 appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err: BusinessError) => { 3418 console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); 3419 }); 3420 ``` 3421 3422### setAccountExtraInfo<sup>(deprecated)</sup> 3423 3424setAccountExtraInfo(name: string, extraInfo: string): Promise<void> 3425 3426Sets additional information for an application account. This API uses a promise to return the result. 3427 3428> **NOTE** 3429> 3430> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9-1) instead. 3431 3432 3433**System capability**: SystemCapability.Account.AppAccount 3434 3435**Parameters** 3436 3437| Name | Type | Mandatory | Description | 3438| --------- | ------ | ---- | --------- | 3439| name | string | Yes | Name of the target application account. | 3440| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token.| 3441 3442**Return value** 3443 3444| Type | Description | 3445| :------------------ | :-------------------- | 3446| Promise<void> | Promise that returns no value.| 3447 3448**Example** 3449 3450 ```ts 3451 import { BusinessError } from '@kit.BasicServicesKit'; 3452 3453 appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => { 3454 console.log('setAccountExtraInfo Success'); 3455 }).catch((err: BusinessError) => { 3456 console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); 3457 }); 3458 ``` 3459 3460### setAppAccountSyncEnable<sup>(deprecated)</sup> 3461 3462setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void 3463 3464Sets data synchronization for an application account. This API uses an asynchronous callback to return the result. 3465 3466> **NOTE** 3467> 3468> This API is supported since API version 7 and deprecated since API version 9. Use [setDataSyncEnabled](#setdatasyncenabled9) instead. 3469 3470**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3471 3472**System capability**: SystemCapability.Account.AppAccount 3473 3474**Parameters** 3475 3476| Name | Type | Mandatory | Description | 3477| -------- | ------------------------- | ---- | ------------------------- | 3478| name | string | Yes | Name of the target application account. | 3479| isEnable | boolean | Yes | Whether to enable data synchronization. | 3480| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3481 3482**Example** 3483 3484 ```ts 3485 import { BusinessError } from '@kit.BasicServicesKit'; 3486 3487 appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err: BusinessError) => { 3488 console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); 3489 }); 3490 ``` 3491 3492### setAppAccountSyncEnable<sup>(deprecated)</sup> 3493 3494setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> 3495 3496Sets data synchronization for an application account. This API uses a promise to return the result. 3497 3498> **NOTE** 3499> 3500> This API is supported since API version 7 and deprecated since API version 9. Use [setDataSyncEnabled](#setdatasyncenabled9-1) instead. 3501 3502**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3503 3504**System capability**: SystemCapability.Account.AppAccount 3505 3506**Parameters** 3507 3508| Name | Type | Mandatory | Description | 3509| -------- | ------- | ---- | ----------- | 3510| name | string | Yes | Name of the target application account. | 3511| isEnable | boolean | Yes | Whether to enable data synchronization.| 3512 3513**Return value** 3514 3515| Type | Description | 3516| :------------------ | :-------------------- | 3517| Promise<void> | Promise that returns no value.| 3518 3519**Example** 3520 3521 ```ts 3522 import { BusinessError } from '@kit.BasicServicesKit'; 3523 3524 appAccountManager .setAppAccountSyncEnable('ZhangSan', true).then(() => { 3525 console.log('setAppAccountSyncEnable Success'); 3526 }).catch((err: BusinessError) => { 3527 console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); 3528 }); 3529 ``` 3530 3531### setAssociatedData<sup>(deprecated)</sup> 3532 3533setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void 3534 3535Sets data to be associated with an application account. This API uses an asynchronous callback to return the result. 3536 3537> **NOTE** 3538> 3539> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9) instead. 3540 3541 3542**System capability**: SystemCapability.Account.AppAccount 3543 3544**Parameters** 3545 3546| Name | Type | Mandatory | Description | 3547| -------- | ------------------------- | ---- | ----------------- | 3548| name | string | Yes | Name of the target application account. | 3549| key | string | Yes | Key of the data to set.| 3550| value | string | Yes | Value of the data to set. | 3551| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3552 3553**Example** 3554 3555 ```ts 3556 import { BusinessError } from '@kit.BasicServicesKit'; 3557 3558 appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err: BusinessError) => { 3559 console.log('setAssociatedData err: ' + JSON.stringify(err)); 3560 }); 3561 ``` 3562 3563### setAssociatedData<sup>(deprecated)</sup> 3564 3565setAssociatedData(name: string, key: string, value: string): Promise<void> 3566 3567Sets data to be associated with an application account. This API uses a promise to return the result. 3568 3569> **NOTE** 3570> 3571> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9-1) instead. 3572 3573 3574**System capability**: SystemCapability.Account.AppAccount 3575 3576**Parameters** 3577 3578| Name | Type | Mandatory | Description | 3579| ----- | ------ | ---- | ----------------- | 3580| name | string | Yes | Name of the target application account. | 3581| key | string | Yes | Key of the data to set.| 3582| value | string | Yes | Value of the data to set.| 3583 3584**Return value** 3585 3586| Type | Description | 3587| :------------------ | :-------------------- | 3588| Promise<void> | Promise that returns no value.| 3589 3590**Example** 3591 3592 ```ts 3593 import { BusinessError } from '@kit.BasicServicesKit'; 3594 3595 appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => { 3596 console.log('setAssociatedData Success'); 3597 }).catch((err: BusinessError) => { 3598 console.log('setAssociatedData err: ' + JSON.stringify(err)); 3599 }); 3600 ``` 3601 3602### getAllAccessibleAccounts<sup>(deprecated)</sup> 3603 3604getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 3605 3606Obtains information about all accessible application accounts. This API uses an asynchronous callback to return the result. 3607 3608> **NOTE** 3609> 3610> This API is supported since API version 7 and deprecated since API version 9. Use [getAllAccounts](#getallaccounts9) instead. 3611 3612**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3613 3614**System capability**: SystemCapability.Account.AppAccount 3615 3616**Parameters** 3617 3618| Name | Type | Mandatory | Description | 3619| -------- | ---------------------------------------- | ---- | --------- | 3620| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible application accounts. Otherwise, **err** is an error object.| 3621 3622**Example** 3623 3624 ```ts 3625 import { BusinessError } from '@kit.BasicServicesKit'; 3626 3627 appAccountManager.getAllAccessibleAccounts((err: BusinessError, data: appAccount.AppAccountInfo[])=>{ 3628 console.debug('getAllAccessibleAccounts err: ' + JSON.stringify(err)); 3629 console.debug('getAllAccessibleAccounts data: ' + JSON.stringify(data)); 3630 }); 3631 ``` 3632 3633### getAllAccessibleAccounts<sup>(deprecated)</sup> 3634 3635getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> 3636 3637Obtains information about all accessible application accounts. This API uses a promise to return the result. 3638 3639> **NOTE** 3640> 3641> This API is supported since API version 7 and deprecated since API version 9. Use [getAllAccounts](#getallaccounts9-1) instead. 3642 3643**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3644 3645**System capability**: SystemCapability.Account.AppAccount 3646 3647**Return value** 3648 3649| Type | Description | 3650| ---------------------------------------- | --------------------- | 3651| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return information about all accessible accounts.| 3652 3653**Example** 3654 3655 ```ts 3656 import { BusinessError } from '@kit.BasicServicesKit'; 3657 3658 appAccountManager.getAllAccessibleAccounts().then((data: appAccount.AppAccountInfo[]) => { 3659 console.log('getAllAccessibleAccounts: ' + data); 3660 }).catch((err: BusinessError) => { 3661 console.log('getAllAccessibleAccounts err: ' + JSON.stringify(err)); 3662 }); 3663 ``` 3664 3665### getAllAccounts<sup>(deprecated)</sup> 3666 3667getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void 3668 3669Obtains the application accounts that can be accessed by the invoker based on the application account owner. This API uses an asynchronous callback to return the result. 3670 3671> **NOTE** 3672> 3673> This API is supported since API version 7 and deprecated since API version 9. Use [getAccountsByOwner](#getaccountsbyowner9) instead. 3674 3675**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3676 3677**System capability**: SystemCapability.Account.AppAccount 3678 3679**Parameters** 3680 3681| Name | Type | Mandatory | Description | 3682| -------- | ---------------------------------------- | ---- | --------- | 3683| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 3684| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return information about all accessible application accounts.| 3685 3686**Example** 3687 3688 ```ts 3689 import { BusinessError } from '@kit.BasicServicesKit'; 3690 3691 const selfBundle = 'com.example.actsgetallaaccounts'; 3692 appAccountManager.getAllAccounts(selfBundle, (err: BusinessError, data: appAccount.AppAccountInfo[])=>{ 3693 console.debug('getAllAccounts err: ' + JSON.stringify(err)); 3694 console.debug('getAllAccounts data:' + JSON.stringify(data)); 3695 }); 3696 ``` 3697 3698### getAllAccounts<sup>(deprecated)</sup> 3699 3700getAllAccounts(owner: string): Promise<Array<AppAccountInfo>> 3701 3702Obtains the application accounts that can be accessed by the invoker based on the application account owner. This API uses a promise to return the result. 3703 3704> **NOTE** 3705> 3706> This API is supported since API version 7 and deprecated since API version 9. Use [getAccountsByOwner](#getaccountsbyowner9-1) instead. 3707 3708**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3709 3710**System capability**: SystemCapability.Account.AppAccount 3711 3712**Parameters** 3713 3714| Name | Type | Mandatory | Description | 3715| ----- | ------ | ---- | ------ | 3716| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 3717 3718**Return value** 3719 3720| Type | Description | 3721| ---------------------------------------- | --------------------- | 3722| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the application accounts that can be accessed by the invoker.| 3723 3724**Example** 3725 3726 ```ts 3727 import { BusinessError } from '@kit.BasicServicesKit'; 3728 3729 const selfBundle = 'com.example.actsgetallaaccounts'; 3730 appAccountManager.getAllAccounts(selfBundle).then((data: appAccount.AppAccountInfo[]) => { 3731 console.log('getAllAccounts: ' + data); 3732 }).catch((err: BusinessError) => { 3733 console.log('getAllAccounts err: ' + JSON.stringify(err)); 3734 }); 3735 ``` 3736 3737### getAccountCredential<sup>(deprecated)</sup> 3738 3739getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 3740 3741Obtains the credential of an application account. This API uses an asynchronous callback to return the result. 3742 3743> **NOTE** 3744> 3745> This API is supported since API version 7 and deprecated since API version 9. Use [getCredential](#getcredential9) instead. 3746 3747**System capability**: SystemCapability.Account.AppAccount 3748 3749**Parameters** 3750 3751| Name | Type | Mandatory | Description | 3752| -------------- | --------------------------- | ---- | -------------- | 3753| name | string | Yes | Name of the target application account. | 3754| credentialType | string | Yes | Type of the credential to obtain.| 3755| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| 3756 3757**Example** 3758 3759 ```ts 3760 import { BusinessError } from '@kit.BasicServicesKit'; 3761 3762 appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err: BusinessError, result: string) => { 3763 console.log('getAccountCredential err: ' + JSON.stringify(err)); 3764 console.log('getAccountCredential result: ' + result); 3765 }); 3766 ``` 3767 3768### getAccountCredential<sup>(deprecated)</sup> 3769 3770getAccountCredential(name: string, credentialType: string): Promise<string> 3771 3772Obtains the credential of an application account. This API uses a promise to return the result. 3773 3774> **NOTE** 3775> 3776> This API is supported since API version 7 and deprecated since API version 9. Use [getCredential](#getcredential9-1) instead. 3777 3778**System capability**: SystemCapability.Account.AppAccount 3779 3780**Parameters** 3781 3782| Name | Type | Mandatory | Description | 3783| -------------- | ------ | ---- | ---------- | 3784| name | string | Yes | Name of the target application account. | 3785| credentialType | string | Yes | Type of the credential to obtain.| 3786 3787**Return value** 3788 3789| Type | Description | 3790| :-------------------- | :-------------------- | 3791| Promise<string> | Promise used to return the credential obtained.| 3792 3793**Example** 3794 3795 ```ts 3796 import { BusinessError } from '@kit.BasicServicesKit'; 3797 3798 appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data: string) => { 3799 console.log('getAccountCredential, result: ' + data); 3800 }).catch((err: BusinessError) => { 3801 console.log('getAccountCredential err: ' + JSON.stringify(err)); 3802 }); 3803 ``` 3804 3805### getAccountExtraInfo<sup>(deprecated)</sup> 3806 3807getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void 3808 3809Obtains additional information of an application account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the application account password and token. This API uses an asynchronous callback to return the result. 3810 3811> **NOTE** 3812> 3813> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9) instead. 3814 3815**System capability**: SystemCapability.Account.AppAccount 3816 3817**Parameters** 3818 3819| Name | Type | Mandatory | Description | 3820| -------- | --------------------------- | ---- | --------------- | 3821| name | string | Yes | Name of the target application account. | 3822| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the additional information obtained. Otherwise, **err** is an error object.| 3823 3824**Example** 3825 3826 ```ts 3827 import { BusinessError } from '@kit.BasicServicesKit'; 3828 3829 appAccountManager.getAccountExtraInfo('ZhangSan', (err: BusinessError, result: string) => { 3830 console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); 3831 console.log('getAccountExtraInfo result: ' + result); 3832 }); 3833 ``` 3834 3835### getAccountExtraInfo<sup>(deprecated)</sup> 3836 3837getAccountExtraInfo(name: string): Promise<string> 3838 3839Obtains additional information of an application account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the application account password and token. This API uses a promise to return the result. 3840 3841> **NOTE** 3842> 3843> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9-1) instead. 3844 3845**System capability**: SystemCapability.Account.AppAccount 3846 3847**Parameters** 3848 3849| Name | Type | Mandatory | Description | 3850| ---- | ------ | ---- | ------- | 3851| name | string | Yes | Name of the target application account.| 3852 3853**Return value** 3854 3855| Type | Description | 3856| :-------------------- | :-------------------- | 3857| Promise<string> | Promise used to return the additional information obtained.| 3858 3859**Example** 3860 3861 ```ts 3862 import { BusinessError } from '@kit.BasicServicesKit'; 3863 3864 appAccountManager.getAccountExtraInfo('ZhangSan').then((data: string) => { 3865 console.log('getAccountExtraInfo, result: ' + data); 3866 }).catch((err: BusinessError) => { 3867 console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); 3868 }); 3869 ``` 3870 3871### getAssociatedData<sup>(deprecated)</sup> 3872 3873getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void 3874 3875Obtains data associated with an application account. This API uses an asynchronous callback to return the result. 3876 3877> **NOTE** 3878> 3879> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9) instead. 3880 3881**System capability**: SystemCapability.Account.AppAccount 3882 3883**Parameters** 3884 3885| Name | Type | Mandatory | Description | 3886| -------- | --------------------------- | ---- | ----------------- | 3887| name | string | Yes | Name of the target application account. | 3888| key | string | Yes | Key of the data to obtain. | 3889| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the data obtained. Otherwise, **err** is an error object.| 3890 3891**Example** 3892 3893 ```ts 3894 import { BusinessError } from '@kit.BasicServicesKit'; 3895 3896 appAccountManager.getAssociatedData('ZhangSan', 'k001', (err: BusinessError, result: string) => { 3897 console.log('getAssociatedData err: ' + JSON.stringify(err)); 3898 console.log('getAssociatedData result: ' + result); 3899 }); 3900 ``` 3901 3902### getAssociatedData<sup>(deprecated)</sup> 3903 3904getAssociatedData(name: string, key: string): Promise<string> 3905 3906Obtains data associated with an application account. This API uses a promise to return the result. 3907 3908> **NOTE** 3909> 3910> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9-1) instead. 3911 3912**System capability**: SystemCapability.Account.AppAccount 3913 3914**Parameters** 3915 3916| Name | Type | Mandatory | Description | 3917| ---- | ------ | ---- | --------- | 3918| name | string | Yes | Name of the target application account. | 3919| key | string | Yes | Key of the data to obtain.| 3920 3921**Return value** 3922 3923| Type | Description | 3924| :-------------------- | :-------------------- | 3925| Promise<string> | Promise used to return the data obtained.| 3926 3927**Example** 3928 3929 ```ts 3930 import { BusinessError } from '@kit.BasicServicesKit'; 3931 3932 appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data: string) => { 3933 console.log('getAssociatedData: ' + data); 3934 }).catch((err: BusinessError) => { 3935 console.log('getAssociatedData err: ' + JSON.stringify(err)); 3936 }); 3937 ``` 3938 3939### on('change')<sup>(deprecated)</sup> 3940 3941on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 3942 3943Subscribes to account information changes of apps. 3944 3945> **NOTE** 3946> 3947> This API is supported since API version 7 and deprecated since API version 9. Use [on('accountChange')](#onaccountchange9) instead. 3948 3949**System capability**: SystemCapability.Account.AppAccount 3950 3951**Parameters** 3952 3953| Name | Type | Mandatory | Description | 3954| -------- | ---------------------------------------- | ---- | ------------------------------ | 3955| type | 'change' | Yes | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes.| 3956| owners | Array<string> | Yes | application bundle names of the account. | 3957| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback registered to return the list of changed application accounts. | 3958 3959**Example** 3960 3961 ```ts 3962 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 3963 console.debug('receive change data:' + JSON.stringify(data)); 3964 } 3965 try{ 3966 appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback); 3967 } 3968 catch(err){ 3969 console.error('on accountOnOffDemo err:' + JSON.stringify(err)); 3970 } 3971 ``` 3972 3973### off('change')<sup>(deprecated)</sup> 3974 3975off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void 3976 3977Unsubscribes from account information changes. 3978 3979> **NOTE** 3980> 3981> This API is supported since API version 7 and deprecated since API version 9. Use [off('accountChange')](#offaccountchange9) instead. 3982 3983**System capability**: SystemCapability.Account.AppAccount 3984 3985**Parameters** 3986 3987| Name | Type | Mandatory | Description | 3988| -------- | -------------------------------- | ---- | ------------ | 3989| type | 'change' | Yes | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes. | 3990| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | No | Callback to unregister. By default, no value is passed, which means to unregister all callbacks for the specified event.| 3991 3992**Example** 3993 3994 ```ts 3995 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 3996 console.debug('receive change data: ' + JSON.stringify(data)); 3997 appAccountManager.off('change', () => { 3998 console.debug('off finish'); 3999 }) 4000 } 4001 try{ 4002 appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback); 4003 } 4004 catch(err){ 4005 console.error('on accountOnOffDemo err: ' + JSON.stringify(err)); 4006 } 4007 ``` 4008 4009### authenticate<sup>(deprecated)</sup> 4010 4011authenticate(name: string, owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 4012 4013Authenticates an application account. This API uses an asynchronous callback to return the result. 4014 4015> **NOTE** 4016> 4017> This API is supported since API version 8 and deprecated since API version 9. Use [auth](#auth9) instead. 4018 4019**System capability**: SystemCapability.Account.AppAccount 4020 4021**Parameters** 4022 4023| Name | Type | Mandatory | Description | 4024| -------- | --------------------- | ---- | --------------- | 4025| name | string | Yes | Name of the target application account. | 4026| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 4027| authType | string | Yes | Authentication type. | 4028| options | {[key: string]: any} | Yes | Options for the authentication. | 4029| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the result.| 4030 4031**Example** 4032 4033 ```ts 4034 import { BusinessError } from '@kit.BasicServicesKit'; 4035 import { Want, common } from '@kit.AbilityKit'; 4036 4037 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 4038 4039 function onResultCallback(code: number, result: Record<string, Object>): void { 4040 console.log('resultCode: ' + code); 4041 console.log('result: ' + JSON.stringify(result)); 4042 } 4043 4044 function onRequestRedirectedCallback(request: Want): void { 4045 let wantInfo: Want = { 4046 deviceId: '', 4047 bundleName: 'com.example.accountjsdemo', 4048 action: 'ohos.want.action.viewData', 4049 entities: ['entity.system.default'], 4050 } 4051 context.startAbility(wantInfo).then(() => { 4052 console.log('startAbility successfully'); 4053 }).catch((err: BusinessError) => { 4054 console.log('startAbility err: ' + JSON.stringify(err)); 4055 }) 4056 } 4057 4058 appAccountManager.authenticate('LiSi', 'com.example.accountjsdemo', 'getSocialData', {}, { 4059 onResult: onResultCallback, 4060 onRequestRedirected: onRequestRedirectedCallback 4061 }); 4062 ``` 4063 4064### getOAuthToken<sup>(deprecated)</sup> 4065 4066getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 4067 4068Obtains the authorization token of the specified authentication type for an application account. This API uses an asynchronous callback to return the result. 4069 4070> **NOTE** 4071> 4072> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthToken](#getauthtoken9) instead. 4073 4074**System capability**: SystemCapability.Account.AppAccount 4075 4076**Parameters** 4077 4078| Name | Type | Mandatory | Description | 4079| -------- | --------------------------- | ---- | ----------- | 4080| name | string | Yes | Name of the target application account. | 4081| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4082| authType | string | Yes | Authentication type. | 4083| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | 4084 4085**Example** 4086 4087 ```ts 4088 import { BusinessError } from '@kit.BasicServicesKit'; 4089 4090 appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 4091 (err: BusinessError, data: string) => { 4092 console.log('getOAuthToken err: ' + JSON.stringify(err)); 4093 console.log('getOAuthToken token: ' + data); 4094 }); 4095 ``` 4096 4097### getOAuthToken<sup>(deprecated)</sup> 4098 4099getOAuthToken(name: string, owner: string, authType: string): Promise<string> 4100 4101Obtains the authorization token of the specified authentication type for an application account. This API uses a promise to return the result. 4102 4103> **NOTE** 4104> 4105> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthToken](#getauthtoken9-1) instead. 4106 4107**System capability**: SystemCapability.Account.AppAccount 4108 4109**Parameters** 4110 4111| Name | Type | Mandatory | Description | 4112| -------- | ------ | ---- | ----------- | 4113| name | string | Yes | Name of the target application account. | 4114| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4115| authType | string | Yes | Authentication type. | 4116 4117**Return value** 4118 4119| Type | Description | 4120| --------------------- | --------------------- | 4121| Promise<string> | Promise used to return the authorization token obtained.| 4122 4123**Example** 4124 4125 ```ts 4126 import { BusinessError } from '@kit.BasicServicesKit'; 4127 4128 appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data: string) => { 4129 console.log('getOAuthToken token: ' + data); 4130 }).catch((err: BusinessError) => { 4131 console.log('getOAuthToken err: ' + JSON.stringify(err)); 4132 }); 4133 ``` 4134 4135### setOAuthToken<sup>(deprecated)</sup> 4136 4137setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 4138 4139Sets an authorization token of the specific authentication type for an application account. This API uses an asynchronous callback to return the result. 4140 4141> **NOTE** 4142> 4143> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthToken](#setauthtoken9) instead. 4144 4145**System capability**: SystemCapability.Account.AppAccount 4146 4147**Parameters** 4148 4149| Name | Type | Mandatory | Description | 4150| -------- | ------------------------- | ---- | -------- | 4151| name | string | Yes | Name of the target application account.| 4152| authType | string | Yes | Authentication type. | 4153| token | string | Yes | Authorization token to set.| 4154| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 4155 4156**Example** 4157 4158 ```ts 4159 import { BusinessError } from '@kit.BasicServicesKit'; 4160 4161 appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => { 4162 console.log('setOAuthToken err: ' + JSON.stringify(err)); 4163 }); 4164 ``` 4165 4166### setOAuthToken<sup>(deprecated)</sup> 4167 4168setOAuthToken(name: string, authType: string, token: string): Promise<void> 4169 4170Sets an authorization token of the specific authentication type for an application account. This API uses a promise to return the result. 4171 4172> **NOTE** 4173> 4174> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthToken](#setauthtoken9-1) instead. 4175 4176**System capability**: SystemCapability.Account.AppAccount 4177 4178**Parameters** 4179 4180| Name | Type | Mandatory | Description | 4181| -------- | ------ | ---- | -------- | 4182| name | string | Yes | Name of the target application account.| 4183| authType | string | Yes | Authentication type. | 4184| token | string | Yes | Authorization token to set.| 4185 4186**Return value** 4187 4188| Type | Description | 4189| ------------------- | --------------------- | 4190| Promise<void> | Promise that returns no value.| 4191 4192**Example** 4193 4194 ```ts 4195 import { BusinessError } from '@kit.BasicServicesKit'; 4196 4197 appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { 4198 console.log('setOAuthToken successfully'); 4199 }).catch((err: BusinessError) => { 4200 console.log('setOAuthToken err: ' + JSON.stringify(err)); 4201 }); 4202 ``` 4203 4204### deleteOAuthToken<sup>(deprecated)</sup> 4205 4206deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 4207 4208Deletes the authorization token of the specified authentication type for an application account. This API uses an asynchronous callback to return the result. 4209 4210> **NOTE** 4211> 4212> This API is supported since API version 8 and deprecated since API version 9. Use [deleteAuthToken](#deleteauthtoken9) instead. 4213 4214**System capability**: SystemCapability.Account.AppAccount 4215 4216**Parameters** 4217 4218| Name | Type | Mandatory | Description | 4219| -------- | ------------------------- | ---- | ------------ | 4220| name | string | Yes | Name of the target application account. | 4221| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 4222| authType | string | Yes | Authentication type. | 4223| token | string | Yes | Authorization token to delete.| 4224| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4225 4226**Example** 4227 4228 ```ts 4229 import { BusinessError } from '@kit.BasicServicesKit'; 4230 4231 appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', 4232 (err: BusinessError) => { 4233 console.log('deleteOAuthToken err: ' + JSON.stringify(err)); 4234 }); 4235 ``` 4236 4237### deleteOAuthToken<sup>(deprecated)</sup> 4238 4239deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 4240 4241Deletes the authorization token of the specified authentication type for an application account. This API uses a promise to return the result. 4242 4243> **NOTE** 4244> 4245> This API is supported since API version 8 and deprecated since API version 9. Use [deleteAuthToken](#deleteauthtoken9-1) instead. 4246 4247**System capability**: SystemCapability.Account.AppAccount 4248 4249**Parameters** 4250 4251| Name | Type | Mandatory | Description | 4252| -------- | ------ | ---- | ------------ | 4253| name | string | Yes | Name of the target application account. | 4254| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. | 4255| authType | string | Yes | Authentication type. | 4256| token | string | Yes | Authorization token to delete.| 4257 4258**Return value** 4259 4260| Type | Description | 4261| ------------------- | --------------------- | 4262| Promise<void> | Promise that returns no value.| 4263 4264**Example** 4265 4266 ```ts 4267 import { BusinessError } from '@kit.BasicServicesKit'; 4268 4269 appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { 4270 console.log('deleteOAuthToken successfully'); 4271 }).catch((err: BusinessError) => { 4272 console.log('deleteOAuthToken err: ' + JSON.stringify(err)); 4273 }); 4274 ``` 4275 4276### setOAuthTokenVisibility<sup>(deprecated)</sup> 4277 4278setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 4279 4280Sets the visibility of an authorization token to an application. This API uses an asynchronous callback to return the result. 4281 4282> **NOTE** 4283> 4284> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthTokenVisibility](#setauthtokenvisibility9) instead. 4285 4286**System capability**: SystemCapability.Account.AppAccount 4287 4288**Parameters** 4289 4290| Name | Type | Mandatory | Description | 4291| ---------- | ------------------------- | ---- | ------------------------- | 4292| name | string | Yes | Name of the target application account. | 4293| authType | string | Yes | Authentication type. | 4294| bundleName | string | Yes | Bundle name of the application. | 4295| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value **true** means the authorization token is visible to the application; the value **false** means the opposite.| 4296| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4297 4298**Example** 4299 4300 ```ts 4301 import { BusinessError } from '@kit.BasicServicesKit'; 4302 4303 appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, 4304 (err: BusinessError) => { 4305 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4306 }); 4307 ``` 4308 4309### setOAuthTokenVisibility<sup>(deprecated)</sup> 4310 4311setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 4312 4313Sets the visibility of an authorization token to an application. This API uses a promise to return the result. 4314 4315> **NOTE** 4316> 4317> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthTokenVisibility](#setauthtokenvisibility9-1) instead. 4318 4319**System capability**: SystemCapability.Account.AppAccount 4320 4321**Parameters** 4322 4323| Name | Type | Mandatory | Description | 4324| ---------- | ------- | ---- | ------------ | 4325| name | string | Yes | Name of the target application account. | 4326| authType | string | Yes | Authentication type. | 4327| bundleName | string | Yes | Bundle name of the application.| 4328| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value **true** means the authorization token is visible to the application; the value **false** means the opposite. | 4329 4330**Return value** 4331 4332| Type | Description | 4333| ------------------- | --------------------- | 4334| Promise<void> | Promise that returns no value.| 4335 4336**Example** 4337 4338 ```ts 4339 import { BusinessError } from '@kit.BasicServicesKit'; 4340 4341 appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { 4342 console.log('setOAuthTokenVisibility successfully'); 4343 }).catch((err: BusinessError) => { 4344 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4345 }); 4346 ``` 4347 4348### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4349 4350checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 4351 4352Checks the visibility of an authorization token of the specified authentication type to an application. This API uses an asynchronous callback to return the result. 4353 4354> **NOTE** 4355> 4356> This API is supported since API version 8 and deprecated since API version 9. Use [checkAuthTokenVisibility](#checkauthtokenvisibility9) instead. 4357 4358**System capability**: SystemCapability.Account.AppAccount 4359 4360**Parameters** 4361 4362| Name | Type | Mandatory | Description | 4363| ---------- | ---------------------------- | ---- | ----------- | 4364| name | string | Yes | Name of the target application account. | 4365| authType | string | Yes | Authentication type. | 4366| bundleName | string | Yes | Bundle name of the application.| 4367| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the application) or **false** (the authorization token is not visible to the application). If the operation fails, **err** is an error object. | 4368 4369**Example** 4370 4371 ```ts 4372 import { BusinessError } from '@kit.BasicServicesKit'; 4373 4374 appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', 4375 (err: BusinessError, data: boolean) => { 4376 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4377 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4378 }); 4379 ``` 4380 4381### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4382 4383checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 4384 4385Checks the visibility of an authorization token of the specified authentication type to an application. This API uses a promise to return the result. 4386 4387> **NOTE** 4388> 4389> This API is supported since API version 8 and deprecated since API version 9. Use [checkAuthTokenVisibility](#checkauthtokenvisibility9-1) instead. 4390 4391**System capability**: SystemCapability.Account.AppAccount 4392 4393**Parameters** 4394 4395| Name | Type | Mandatory | Description | 4396| ---------- | ------ | ---- | ------------- | 4397| name | string | Yes | Name of the target application account. | 4398| authType | string | Yes | Authentication type. | 4399| bundleName | string | Yes | Bundle name of the application.| 4400 4401**Return value** 4402 4403| Type | Description | 4404| ---------------------- | --------------------- | 4405| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the application; the value **false** means the opposite.| 4406 4407**Example** 4408 4409 ```ts 4410 import { BusinessError } from '@kit.BasicServicesKit'; 4411 4412 appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then(( 4413 data: boolean) => { 4414 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4415 }).catch((err: BusinessError) => { 4416 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4417 }); 4418 ``` 4419 4420### getAllOAuthTokens<sup>(deprecated)</sup> 4421 4422getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void 4423 4424Obtains all tokens visible to the invoker for an application account. This API uses an asynchronous callback to return the result. 4425 4426> **NOTE** 4427> 4428> This API is supported since API version 8 and deprecated since API version 9. Use [getAllAuthTokens](#getallauthtokens9) instead. 4429 4430**System capability**: SystemCapability.Account.AppAccount 4431 4432**Parameters** 4433 4434| Name | Type | Mandatory | Description | 4435| -------- | ---------------------------------------- | ---- | ----------- | 4436| name | string | Yes | Name of the target application account. | 4437| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4438| callback | AsyncCallback<Array<[OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | 4439 4440**Example** 4441 4442 ```ts 4443 import { BusinessError } from '@kit.BasicServicesKit'; 4444 4445 appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo', 4446 (err: BusinessError, data: appAccount.OAuthTokenInfo[]) => { 4447 console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); 4448 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4449 }); 4450 ``` 4451 4452### getAllOAuthTokens<sup>(deprecated)</sup> 4453 4454getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> 4455 4456Obtains all tokens visible to the invoker for an application account. This API uses a promise to return the result. 4457 4458> **NOTE** 4459> 4460> This API is supported since API version 8 and deprecated since API version 9. Use [getAllAuthTokens](#getallauthtokens9-1) instead. 4461 4462**System capability**: SystemCapability.Account.AppAccount 4463 4464**Parameters** 4465 4466| Name | Type | Mandatory | Description | 4467| ----- | ------ | ---- | ----------- | 4468| name | string | Yes | Name of the target application account. | 4469| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4470 4471**Return value** 4472 4473| Type | Description | 4474| ---------------------------------------- | --------------------- | 4475| Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Promise used to return the tokens obtained.| 4476 4477**Example** 4478 4479 ```ts 4480 import { BusinessError } from '@kit.BasicServicesKit'; 4481 4482 appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then(( 4483 data: appAccount.OAuthTokenInfo[]) => { 4484 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4485 }).catch((err: BusinessError) => { 4486 console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); 4487 }); 4488 ``` 4489 4490### getOAuthList<sup>(deprecated)</sup> 4491 4492getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 4493 4494Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses an asynchronous callback to return the result. 4495 4496> **NOTE** 4497> 4498> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthList](#getauthlist9) instead. 4499 4500**System capability**: SystemCapability.Account.AppAccount 4501 4502**Parameters** 4503 4504| Name | Type | Mandatory | Description | 4505| -------- | ---------------------------------------- | ---- | ----------------------- | 4506| name | string | Yes | Name of the target application account. | 4507| authType | string | Yes | Authentication type.| 4508| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object. | 4509 4510**Example** 4511 4512 ```ts 4513 import { BusinessError } from '@kit.BasicServicesKit'; 4514 4515 appAccountManager.getOAuthList('LiSi', 'getSocialData', (err: BusinessError, data: string[]) => { 4516 console.log('getOAuthList err: ' + JSON.stringify(err)); 4517 console.log('getOAuthList data: ' + JSON.stringify(data)); 4518 }); 4519 ``` 4520 4521### getOAuthList<sup>(deprecated)</sup> 4522 4523getOAuthList(name: string, authType: string): Promise<Array<string>> 4524 4525Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses a promise to return the result. 4526 4527> **NOTE** 4528> 4529> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthList](#getauthlist9-1) instead. 4530 4531**System capability**: SystemCapability.Account.AppAccount 4532 4533**Parameters** 4534 4535| Name | Type | Mandatory | Description | 4536| -------- | ------ | ---- | ----------------------- | 4537| name | string | Yes | Name of the target application account. | 4538| authType | string | Yes | Authentication type.| 4539 4540**Return value** 4541 4542| Type | Description | 4543| ---------------------------------- | --------------------- | 4544| Promise<Array<string>> | Promise used to return a list of authorized bundles.| 4545 4546**Example** 4547 4548 ```ts 4549 import { BusinessError } from '@kit.BasicServicesKit'; 4550 4551 appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data: string[]) => { 4552 console.log('getOAuthList data: ' + JSON.stringify(data)); 4553 }).catch((err: BusinessError) => { 4554 console.log('getOAuthList err: ' + JSON.stringify(err)); 4555 }); 4556 ``` 4557 4558### getAuthenticatorCallback<sup>(deprecated)</sup> 4559 4560getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void 4561 4562Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. 4563 4564> **NOTE** 4565> 4566> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthCallback](#getauthcallback9) instead. 4567 4568**System capability**: SystemCapability.Account.AppAccount 4569 4570**Parameters** 4571 4572| Name | Type | Mandatory | Description | 4573| --------- | ---------------------------------------- | ---- | -------- | 4574| sessionId | string | Yes | ID of the authentication session.| 4575| callback | AsyncCallback<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback obtained. Otherwise, **err** is an error object.| 4576 4577**Example** 4578 4579 ```ts 4580 import { BusinessError } from '@kit.BasicServicesKit'; 4581 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 4582 4583 export default class EntryAbility extends UIAbility { 4584 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 4585 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 4586 appAccountManager.getAuthenticatorCallback(sessionId, 4587 (err: BusinessError, callback: appAccount.AuthenticatorCallback) => { 4588 if (err.code != appAccount.ResultCode.SUCCESS) { 4589 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 4590 return; 4591 } 4592 callback.onResult(appAccount.ResultCode.SUCCESS, { 4593 name: 'LiSi', 4594 owner: 'com.example.accountjsdemo', 4595 authType: 'getSocialData', 4596 token: 'xxxxxx'} 4597 ); 4598 }); 4599 } 4600 } 4601 ``` 4602 4603### getAuthenticatorCallback<sup>(deprecated)</sup> 4604 4605getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> 4606 4607Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. 4608 4609> **NOTE** 4610> 4611> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthCallback](#getauthcallback9-1) instead. 4612 4613**System capability**: SystemCapability.Account.AppAccount 4614 4615**Parameters** 4616 4617| Name | Type | Mandatory | Description | 4618| --------- | ------ | ---- | -------- | 4619| sessionId | string | Yes | ID of the authentication session.| 4620 4621**Return value** 4622 4623| Type | Description | 4624| ------------------------------------ | --------------------- | 4625| Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Promise used to return the authenticator callback obtained.| 4626 4627**Example** 4628 4629 ```ts 4630 import { BusinessError } from '@kit.BasicServicesKit'; 4631 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 4632 4633 export default class EntryAbility extends UIAbility { 4634 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 4635 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 4636 appAccountManager.getAuthenticatorCallback(sessionId).then(( 4637 callback: appAccount.AuthenticatorCallback) => { 4638 callback.onResult(appAccount.ResultCode.SUCCESS, { 4639 name: 'LiSi', 4640 owner: 'com.example.accountjsdemo', 4641 authType: 'getSocialData', 4642 token: 'xxxxxx'} 4643 ); 4644 }).catch((err: BusinessError) => { 4645 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 4646 }); 4647 } 4648 } 4649 ``` 4650 4651### getAuthenticatorInfo<sup>(deprecated)</sup> 4652 4653getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 4654 4655Obtains the authenticator information of an application. This API uses an asynchronous callback to return the result. 4656 4657> **NOTE** 4658> 4659> This API is supported since API version 8 and deprecated since API version 9. Use [queryAuthenticatorInfo](#queryauthenticatorinfo9) instead. 4660 4661**System capability**: SystemCapability.Account.AppAccount 4662 4663**Parameters** 4664 4665| Name | Type | Mandatory | Description | 4666| -------- | -------------------------------------- | ---- | ----------- | 4667| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4668| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | 4669 4670**Example** 4671 4672 ```ts 4673 import { BusinessError } from '@kit.BasicServicesKit'; 4674 4675 appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo', 4676 (err: BusinessError, data: appAccount.AuthenticatorInfo) => { 4677 console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); 4678 console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); 4679 }); 4680 ``` 4681 4682### getAuthenticatorInfo<sup>(deprecated)</sup> 4683 4684getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 4685 4686Obtains the authenticator information of an application. This API uses a promise to return the result. 4687 4688> **NOTE** 4689> 4690> This API is supported since API version 8 and deprecated since API version 9. Use [queryAuthenticatorInfo](#queryauthenticatorinfo9-1) instead. 4691 4692**System capability**: SystemCapability.Account.AppAccount 4693 4694**Parameters** 4695 4696| Name | Type | Mandatory | Description | 4697| ----- | ------ | ---- | ----------- | 4698| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4699 4700**Return value** 4701 4702| Type | Description | 4703| -------------------------------- | --------------------- | 4704| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| 4705 4706**Example** 4707 4708 ```ts 4709 import { BusinessError } from '@kit.BasicServicesKit'; 4710 4711 appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then(( 4712 data: appAccount.AuthenticatorInfo) => { 4713 console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); 4714 }).catch((err: BusinessError) => { 4715 console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); 4716 }); 4717 ``` 4718 4719## AppAccountInfo 4720 4721Defines application account information. 4722 4723**System capability**: SystemCapability.Account.AppAccount 4724 4725| Name | Type | Mandatory | Description | 4726| ----- | ------ | ---- | ----------- | 4727| owner | string | Yes | Owner of the application account. The value is the bundle name of the application.| 4728| name | string | Yes | Name of the target application account. | 4729 4730## AuthTokenInfo<sup>9+</sup> 4731 4732Defines authorization token information. 4733 4734**System capability**: SystemCapability.Account.AppAccount 4735 4736| Name | Type | Mandatory | Description | 4737| -------------------- | -------------- | ----- | ---------------- | 4738| authType<sup>9+</sup> | string | Yes | Authentication type. | 4739| token<sup>9+</sup> | string | Yes | Value of the authorization token. | 4740| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No | Information about the account to which the token belongs. By default, no value is passed in.| 4741 4742## OAuthTokenInfo<sup>(deprecated)</sup> 4743 4744Defines authorization token information. 4745 4746> **NOTE** 4747> 4748> This API is supported since API version 8 and deprecated since API version 9. Use [AuthTokenInfo](#authtokeninfo9) instead. 4749 4750**System capability**: SystemCapability.Account.AppAccount 4751 4752| Name | Type | Mandatory | Description | 4753| -------------------- | -------------- | ----- | ---------------- | 4754| authType | string | Yes | Authentication type. | 4755| token | string | Yes | Value of the authorization token. | 4756 4757## AuthenticatorInfo<sup>8+</sup> 4758 4759Defines OAuth authenticator information. 4760 4761**System capability**: SystemCapability.Account.AppAccount 4762 4763| Name | Type | Mandatory | Description | 4764| ------- | ------ | ---- | ---------- | 4765| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the application.| 4766| iconId | number | Yes | ID of the authenticator icon. | 4767| labelId | number | Yes | ID of the authenticator label. | 4768 4769## AuthResult<sup>9+</sup> 4770 4771Defines the authentication result. 4772 4773**System capability**: SystemCapability.Account.AppAccount 4774 4775| Name | Type | Mandatory | Description | 4776| ------- | ------ | ---- | ---------- | 4777| account | [AppAccountInfo](#appaccountinfo) | No | Information about the account to which the token belongs. By default, no value is passed in.| 4778| tokenInfo | [AuthTokenInfo](#authtokeninfo9) | No | Token information. By default, no value is passed in. | 4779 4780## CreateAccountOptions<sup>9+</sup> 4781 4782Defines the options for creating an application account. 4783 4784**System capability**: SystemCapability.Account.AppAccount 4785 4786| Name | Type | Mandatory | Description | 4787| ------- | ------ | ---- | ---------- | 4788| customData | Record<string, string> | No | Custom data. By default, no value is passed in.| 4789 4790## CreateAccountImplicitlyOptions<sup>9+</sup> 4791 4792Defines the options for implicitly creating an application account. 4793 4794**System capability**: SystemCapability.Account.AppAccount 4795 4796| Name | Type | Mandatory | Description | 4797| ------- | ------ | ---- | ---------- | 4798| requiredLabels | Array<string> | No | Required labels. By default, no value is passed in.| 4799| authType | string | No | Authentication type. By default, no value is passed in.| 4800| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in.| 4801## SelectAccountsOptions<sup>9+</sup> 4802 4803Defines the options for selecting accounts. 4804 4805**System capability**: SystemCapability.Account.AppAccount 4806 4807| Name | Type | Mandatory | Description | 4808| --------------- | --------------------------- | ----- | ------------------- | 4809| allowedAccounts | Array<[AppAccountInfo](#appaccountinfo)> | No | Array of allowed accounts. By default, no value is passed in. | 4810| allowedOwners | Array<string> | No | Array of the owners of the allowed accounts. By default, no value is passed in.| 4811| requiredLabels | Array<string> | No | Labels of the authenticator. By default, no value is passed in. | 4812 4813## VerifyCredentialOptions<sup>9+</sup> 4814 4815Represents the options for verifying the user credential. 4816 4817**System capability**: SystemCapability.Account.AppAccount 4818 4819| Name | Type | Mandatory | Description | 4820| -------------- | ---------------------- | ----- | -------------- | 4821| credentialType | string | No | Credential type. By default, no value is passed in. | 4822| credential | string | No | Credential value. By default, no value is passed in. | 4823| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in.| 4824 4825 4826## SetPropertiesOptions<sup>9+</sup> 4827 4828Represents the options for setting authenticator properties. 4829 4830**System capability**: SystemCapability.Account.AppAccount 4831 4832| Name | Type | Mandatory | Description | 4833| ---------- | ---------------------- | ----- | -------------- | 4834| properties | Record<string, Object> | No | Property object. By default, no value is passed in. | 4835| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in.| 4836 4837## Constants<sup>8+</sup> 4838 4839Enumerates the constants. 4840 4841**System capability**: SystemCapability.Account.AppAccount 4842 4843| Name | Value | Description | 4844| -------------------------------- | ---------------------- | ----------------------- | 4845| ACTION_ADD_ACCOUNT_IMPLICITLY<sup>(deprecated)</sup> | 'addAccountImplicitly' | Operation of adding an account implicitly. | 4846| ACTION_AUTHENTICATE<sup>(deprecated)</sup> | 'authenticate' | Authentication operation. | 4847| ACTION_CREATE_ACCOUNT_IMPLICITLY<sup>9+</sup> | 'createAccountImplicitly' | Operation of creating an account implicitly. | 4848| ACTION_AUTH<sup>9+</sup> | 'auth' | Authentication operation. | 4849| ACTION_VERIFY_CREDENTIAL<sup>9+</sup> | 'verifyCredential' | Operation of verifying credentials. | 4850| ACTION_SET_AUTHENTICATOR_PROPERTIES<sup>9+</sup> | 'setAuthenticatorProperties' | Operation of setting authenticator properties. | 4851| KEY_NAME | 'name' | Name of the application account. | 4852| KEY_OWNER | 'owner' | Bundle name of the application account owner.| 4853| KEY_TOKEN | 'token' | Token. | 4854| KEY_ACTION | 'action' | Operation. | 4855| KEY_AUTH_TYPE | 'authType' | Authentication type. | 4856| KEY_SESSION_ID | 'sessionId' | Session ID. | 4857| KEY_CALLER_PID | 'callerPid' | PID of the caller. | 4858| KEY_CALLER_UID | 'callerUid' | UID of the caller. | 4859| KEY_CALLER_BUNDLE_NAME | 'callerBundleName' | Bundle name of the caller. | 4860| KEY_REQUIRED_LABELS<sup>9+</sup> | 'requiredLabels' | Required labels. | 4861| KEY_BOOLEAN_RESULT<sup>9+</sup> | 'booleanResult' | Return value of the Boolean type. | 4862 4863## ResultCode<sup>(deprecated)</sup> 4864 4865Enumerates the result codes. 4866 4867> **NOTE**<br> 4868> This enum is supported since API version 8 and deprecated since API version 9. For details, see [Account Management Error Codes](errorcode-account.md). 4869 4870**System capability**: SystemCapability.Account.AppAccount 4871 4872| Name | Value | Description | 4873| ----------------------------------- | ----- | ------------ | 4874| SUCCESS | 0 | The operation is successful. | 4875| ERROR_ACCOUNT_NOT_EXIST | 10001 | The application account does not exist. | 4876| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. | 4877| ERROR_INVALID_PASSWORD | 10003 | The password is invalid. | 4878| ERROR_INVALID_REQUEST | 10004 | The request is invalid. | 4879| ERROR_INVALID_RESPONSE | 10005 | The response is invalid. | 4880| ERROR_NETWORK_EXCEPTION | 10006 | The network is abnormal. | 4881| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist. | 4882| ERROR_OAUTH_CANCELED | 10008 | The authentication is canceled. | 4883| ERROR_OAUTH_LIST_TOO_LARGE | 10009 | The size of the OAuth list exceeds the limit. | 4884| ERROR_OAUTH_SERVICE_BUSY | 10010 | The OAuth service is busy. | 4885| ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | The OAuth service is abnormal. | 4886| ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | The session to be authenticated does not exist. | 4887| ERROR_OAUTH_TIMEOUT | 10013 | The authentication timed out. | 4888| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | The authorization token does not exist.| 4889| ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | The number of OAuth tokens reaches the limit. | 4890| ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | The authentication operation is not supported. | 4891| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | The authentication type is not supported. | 4892| ERROR_PERMISSION_DENIED | 10018 | The required permission is missing. | 4893 4894## AuthCallback<sup>9+</sup> 4895 4896Implements authenticator callbacks. 4897 4898### onResult<sup>9+</sup> 4899 4900onResult: (code: number, result?: AuthResult) => void 4901 4902Called to return the result of an authentication request. 4903 4904**System capability**: SystemCapability.Account.AppAccount 4905 4906**Parameters** 4907 4908| Name | Type | Mandatory | Description | 4909| ------ | -------------------- | ---- | ------ | 4910| code | number | Yes | Authentication result code.| 4911| result | [AuthResult](#authresult9) | No | Authentication result. By default, no value is passed, which means the authentication result is not received. | 4912 4913**Example** 4914 4915 ```ts 4916 import { BusinessError } from '@kit.BasicServicesKit'; 4917 4918 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 4919 let sessionId = '1234'; 4920 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 4921 let result: appAccount.AuthResult = { 4922 account: { 4923 name: 'Lisi', 4924 owner: 'com.example.accountjsdemo', 4925 }, 4926 tokenInfo: { 4927 token: 'xxxxxx', 4928 authType: 'getSocialData' 4929 } 4930 }; 4931 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4932 }).catch((err: BusinessError) => { 4933 console.log('getAuthCallback err: ' + JSON.stringify(err)); 4934 }); 4935 ``` 4936 4937### onRequestRedirected<sup>9+</sup> 4938 4939onRequestRedirected: (request: Want) => void 4940 4941Called to redirect a request. 4942 4943**System capability**: SystemCapability.Account.AppAccount 4944 4945**Parameters** 4946 4947| Name | Type | Mandatory | Description | 4948| ------- | ---- | ---- | ---------- | 4949| request | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Request to be redirected.| 4950 4951**Example** 4952 4953 ```ts 4954 import { Want } from '@kit.AbilityKit'; 4955 4956 class MyAuthenticator extends appAccount.Authenticator { 4957 createAccountImplicitly( 4958 options: appAccount.CreateAccountImplicitlyOptions, callback: appAccount.AuthCallback) { 4959 let want: Want = { 4960 bundleName: 'com.example.accountjsdemo', 4961 abilityName: 'com.example.accountjsdemo.LoginAbility', 4962 }; 4963 callback.onRequestRedirected(want); 4964 } 4965 4966 auth(name: string, authType: string, 4967 options: Record<string, Object>, callback: appAccount.AuthCallback) { 4968 let result: appAccount.AuthResult = { 4969 account: { 4970 name: 'Lisi', 4971 owner: 'com.example.accountjsdemo', 4972 }, 4973 tokenInfo: { 4974 token: 'xxxxxx', 4975 authType: 'getSocialData' 4976 } 4977 }; 4978 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4979 } 4980 } 4981 ``` 4982 4983### onRequestContinued<sup>9+</sup> 4984 4985onRequestContinued?: () => void 4986 4987Called to continue to process the request. 4988 4989**System capability**: SystemCapability.Account.AppAccount 4990 4991**Example** 4992 4993 ```ts 4994 import { BusinessError } from '@kit.BasicServicesKit'; 4995 4996 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 4997 let sessionId = '1234'; 4998 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 4999 if (callback.onRequestContinued != undefined) { 5000 callback.onRequestContinued(); 5001 } 5002 }).catch((err: BusinessError) => { 5003 console.log('getAuthCallback err: ' + JSON.stringify(err)); 5004 }); 5005 ``` 5006 5007## AuthenticatorCallback<sup>(deprecated)</sup> 5008 5009Provides OAuth authenticator callbacks. 5010 5011> **NOTE** 5012> 5013> This API is supported since API version 8 and deprecated since API version 9. Use [AuthCallback](#authcallback9) instead. 5014 5015### onResult<sup>8+</sup> 5016 5017onResult: (code: number, result: {[key: string]: any;}) => void 5018 5019Called to return the result of an authentication request. 5020 5021**System capability**: SystemCapability.Account.AppAccount 5022 5023**Parameters** 5024 5025| Name | Type | Mandatory | Description | 5026| ------ | -------------------- | ---- | ------ | 5027| code | number | Yes | Authentication result code.| 5028| result | {[key: string]: any} | Yes | Authentication result. | 5029 5030**Example** 5031 5032 ```ts 5033 import { BusinessError } from '@kit.BasicServicesKit'; 5034 5035 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 5036 let sessionId = '1234'; 5037 appAccountManager.getAuthenticatorCallback(sessionId).then((callback: appAccount.AuthenticatorCallback) => { 5038 callback.onResult(appAccount.ResultCode.SUCCESS, { 5039 name: 'LiSi', 5040 owner: 'com.example.accountjsdemo', 5041 authType: 'getSocialData', 5042 token: 'xxxxxx'} 5043 ); 5044 }).catch((err: BusinessError) => { 5045 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 5046 }); 5047 ``` 5048 5049### onRequestRedirected<sup>8+</sup> 5050 5051onRequestRedirected: (request: Want) => void 5052 5053Called to redirect a request. 5054 5055**System capability**: SystemCapability.Account.AppAccount 5056 5057**Parameters** 5058 5059| Name | Type | Mandatory | Description | 5060| ------- | ---- | ---- | ---------- | 5061| request | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Request to be redirected.| 5062 5063**Example** 5064 5065 ```ts 5066 import { Want } from '@kit.AbilityKit'; 5067 5068 class MyAuthenticator extends appAccount.Authenticator { 5069 addAccountImplicitly(authType: string, callerBundleName: string, 5070 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5071 let want: Want = { 5072 bundleName: 'com.example.accountjsdemo', 5073 abilityName: 'com.example.accountjsdemo.LoginAbility', 5074 }; 5075 callback.onRequestRedirected(want); 5076 } 5077 5078 authenticate(name: string, authType: string, callerBundleName: string, 5079 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5080 callback.onResult(appAccount.ResultCode.SUCCESS, { 5081 name: name, 5082 authType: authType, 5083 token: 'xxxxxx'} 5084 ); 5085 } 5086 } 5087 ``` 5088 5089## Authenticator<sup>8+</sup> 5090 5091Provides APIs to operate the authenticator. 5092 5093### createAccountImplicitly<sup>9+</sup> 5094 5095createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 5096 5097Creates an application account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. 5098 5099**System capability**: SystemCapability.Account.AppAccount 5100 5101**Parameters** 5102 5103| Name | Type | Mandatory | Description | 5104| ---------------- | --------------------- | ---- | --------------- | 5105| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | 5106| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 5107 5108### addAccountImplicitly<sup>(deprecated)</sup> 5109 5110addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5111 5112Adds an application account implicitly based on the specified authentication type and options. This API uses an asynchronous callback to return the result. 5113 5114> **NOTE** 5115> 5116> This API is supported since API version 8 and deprecated since API version 9. Use [createAccountImplicitly](#createaccountimplicitly9-2) instead. 5117 5118**System capability**: SystemCapability.Account.AppAccount 5119 5120**Parameters** 5121 5122| Name | Type | Mandatory | Description | 5123| ---------------- | --------------------- | ---- | --------------- | 5124| authType | string | Yes | Authentication type. | 5125| callerBundleName | string | Yes | Bundle name of the authentication requester. | 5126| options | {[key: string]: any} | Yes | Options for the authentication. | 5127| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the result.| 5128 5129### auth<sup>9+</sup> 5130 5131auth(name: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void 5132 5133Authenticates an application account to obtain the authorization token. This API uses an asynchronous callback to return the result. 5134 5135**System capability**: SystemCapability.Account.AppAccount 5136 5137**Parameters** 5138 5139| Name | Type | Mandatory | Description | 5140| ---------------- | --------------------- | ---- | --------------- | 5141| name | string | Yes | Name of the target application account. | 5142| authType | string | Yes | Authentication type. | 5143| options | Record<string, Object> | Yes | Options for the authentication. | 5144| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result.| 5145 5146### authenticate<sup>(deprecated)</sup> 5147 5148authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5149 5150Authenticates an application account to obtain the authorization token. This API uses an asynchronous callback to return the result. 5151 5152> **NOTE** 5153> 5154> This API is supported since API version 8 and deprecated since API version 9. Use [auth](#auth9-2) instead. 5155 5156**System capability**: SystemCapability.Account.AppAccount 5157 5158**Parameters** 5159 5160| Name | Type | Mandatory | Description | 5161| ---------------- | --------------------- | ---- | --------------- | 5162| name | string | Yes | Name of the target application account. | 5163| authType | string | Yes | Authentication type. | 5164| callerBundleName | string | Yes | Bundle name of the authentication requester. | 5165| options | {[key: string]: any} | Yes | Options for the authentication. | 5166| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the result.| 5167 5168### verifyCredential<sup>9+</sup> 5169 5170verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void 5171 5172Verifies the credential of an application account. This API uses an asynchronous callback to return the result. 5173 5174**System capability**: SystemCapability.Account.AppAccount 5175 5176**Parameters** 5177 5178| Name | Type | Mandatory | Description | 5179| ---------------- | --------------------- | ---- | --------------- | 5180| name | string | Yes | Name of the target application account. | 5181| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for credential verification. | 5182| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 5183 5184### setProperties<sup>9+</sup> 5185 5186setProperties(options: SetPropertiesOptions, callback: AuthCallback): void 5187 5188Sets the authenticator properties. This API uses an asynchronous callback to return the result. 5189 5190**System capability**: SystemCapability.Account.AppAccount 5191 5192**Parameters** 5193 5194| Name | Type | Mandatory | Description | 5195| ---------------- | --------------------- | ---- | --------------- | 5196| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 5197| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 5198 5199### checkAccountLabels<sup>9+</sup> 5200 5201checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void 5202 5203Checks the account labels. This API uses an asynchronous callback to return the result. 5204 5205**System capability**: SystemCapability.Account.AppAccount 5206 5207**Parameters** 5208 5209| Name | Type | Mandatory | Description | 5210| ---------------- | --------------------- | ---- | --------------- | 5211| name | string | Yes | Name of the target application account. | 5212| labels | Array<string> | Yes | Labels to check. | 5213| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 5214 5215### checkAccountRemovable<sup>9+</sup> 5216 5217checkAccountRemovable(name: string, callback: AuthCallback): void 5218 5219Checks whether an application account can be deleted. This API uses an asynchronous callback to return the result. 5220 5221**System capability**: SystemCapability.Account.AppAccount 5222 5223**Parameters** 5224 5225| Name | Type | Mandatory | Description | 5226| ---------------- | --------------------- | ---- | --------------- | 5227| name | string | Yes | Name of the target application account. | 5228| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 5229 5230### getRemoteObject<sup>9+</sup> 5231 5232getRemoteObject(): rpc.RemoteObject; 5233 5234Obtains the remote object of an authenticator. This API cannot be overloaded. 5235 5236**System capability**: SystemCapability.Account.AppAccount 5237 5238**Example** 5239 5240 <!--code_no_check--> 5241 ```ts 5242 import { rpc } from '@kit.IPCKit'; 5243 import { Want } from '@kit.AbilityKit'; 5244 5245 class MyAuthenticator extends appAccount.Authenticator { 5246 verifyCredential(name: string, 5247 options: appAccount.VerifyCredentialOptions, callback: appAccount.AuthCallback) { 5248 let want: Want = { 5249 bundleName: 'com.example.accountjsdemo', 5250 abilityName: 'com.example.accountjsdemo.VerifyAbility', 5251 parameters: { 5252 name: name 5253 } 5254 }; 5255 callback.onRequestRedirected(want); 5256 } 5257 5258 setProperties(options: appAccount.SetPropertiesOptions, callback: appAccount.AuthCallback) { 5259 let want: Want = { 5260 bundleName: 'com.example.accountjsdemo', 5261 abilityName: 'com.example.accountjsdemo.SetPropertiesAbility', 5262 parameters: { 5263 options: options 5264 } 5265 }; 5266 callback.onRequestRedirected(want); 5267 } 5268 5269 checkAccountLabels(name: string, labels: string[], callback: appAccount.AuthCallback) { 5270 callback.onResult(0); 5271 } 5272 5273 checkAccountRemovable(name: string, callback: appAccount.AuthCallback) { 5274 callback.onResult(0); 5275 } 5276 } 5277 5278 export default { 5279 onConnect(want: Want): rpc.RemoteObject { // serviceAbility lifecycle function, which needs to be placed in serviceAbility. 5280 let authenticator = new MyAuthenticator(); 5281 return authenticator.getRemoteObject(); 5282 } 5283 } 5284 ``` 5285