1# @ohos.account.appAccount (App Account Management) 2 3The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app 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 app account management. 39 40### createAccount<sup>9+</sup> 41 42createAccount(name: string, callback: AsyncCallback<void>): void 43 44Creates an app 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 app 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 app 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 app account to create. | 92| options | [CreateAccountOptions](#createaccountoptions9) | Yes | Options for creating the app 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 app 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 app account to create. | 141| options | [CreateAccountOptions](#createaccountoptions9) | No | Options for creating the app 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 app 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 app account. The value is the bundle name of the app. | 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 app 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 app account. The value is the bundle name of the app. | 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 app 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 app 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 app 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 app 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 app. 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 app account. | 413| bundleName | string | Yes | Bundle name of the app. | 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| 12400001 | Application not found. | 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 app. 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 app account. | 458| bundleName | string | Yes | Bundle name of the app. | 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| 12400001 | Application not found. | 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 app 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 app account. | 506| bundleName | string | Yes | Bundle name of the app. | 507| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means the app 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 app 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 app account. | 550| bundleName | string | Yes | Bundle name of the app. | 551 552**Return value** 553 554| Type | Description | 555| ------------------- | --------------------- | 556| Promise<boolean> | Promise used to return the result. The value **true** means the app 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 app 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 app 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 app 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 app 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 app 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 app account. | 689| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means data synchronization is enabled for the app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app 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 app accounts that can be accessed by the invoker based on the app 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 app account. The value is the bundle name of the app. | 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 app 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| 12400001 | Application not found. | 1273 1274**Example** 1275 1276 ```ts 1277 import { BusinessError } from '@kit.BasicServicesKit'; 1278 1279 try { 1280 appAccountManager.getAccountsByOwner('com.example.accountjsdemo2', 1281 (err: BusinessError, data: appAccount.AppAccountInfo[]) => { 1282 if (err) { 1283 console.debug('getAccountsByOwner failed, error:' + JSON.stringify(err)); 1284 } else { 1285 console.debug('getAccountsByOwner successfully, data:' + JSON.stringify(data)); 1286 } 1287 }); 1288 } catch (err) { 1289 console.debug('getAccountsByOwner exception:' + JSON.stringify(err)); 1290 } 1291 ``` 1292 1293### getAccountsByOwner<sup>9+</sup> 1294 1295getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>> 1296 1297Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. 1298 1299**System capability**: SystemCapability.Account.AppAccount 1300 1301**Parameters** 1302 1303| Name | Type | Mandatory | Description | 1304| ----- | ------ | ---- | ------ | 1305| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1306 1307**Return value** 1308 1309| Type | Description | 1310| ---------------------------------------- | --------------------- | 1311| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the app account information obtained. | 1312 1313**Error codes** 1314 1315| ID | Error Message| 1316| ------- | -------| 1317| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1318| 12300001 | System service exception. | 1319| 12300002 | Invalid owner. | 1320| 12400001 | Application not found. | 1321 1322**Example** 1323 1324 ```ts 1325 import { BusinessError } from '@kit.BasicServicesKit'; 1326 1327 try { 1328 appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then(( 1329 data: appAccount.AppAccountInfo[]) => { 1330 console.debug('getAccountsByOwner successfully, data: ' + JSON.stringify(data)); 1331 }).catch((err: BusinessError) => { 1332 console.debug('getAccountsByOwner failed, error: ' + JSON.stringify(err)); 1333 }); 1334 } catch (err) { 1335 console.debug('getAccountsByOwner exception: ' + JSON.stringify(err)); 1336 } 1337 ``` 1338 1339### on('accountChange')<sup>9+</sup> 1340 1341on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 1342 1343Subscribes to account information changes of apps. 1344 1345**System capability**: SystemCapability.Account.AppAccount 1346 1347**Parameters** 1348 1349| Name | Type | Mandatory | Description | 1350| -------- | ---------------------------------------- | ---- | ------------------------------ | 1351| type | 'accountChange' | Yes | Event type to subscribe to. The value is **'accountChange'**. An event will be reported when the account information of the target app changes. | 1352| owners | Array<string> | Yes | App bundle names of the account. | 1353| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback registered to return the list of changed app accounts. | 1354 1355**Error codes** 1356 1357| ID | Error Message | 1358| ------- | ------- | 1359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1360| 12300001 | System service exception. | 1361| 12300002 | Invalid type or owners. | 1362| 12400001 | Application not found. | 1363 1364**Example** 1365 1366 ```ts 1367 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 1368 console.log('receive change data:' + JSON.stringify(data)); 1369 } 1370 try{ 1371 appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback); 1372 } catch(err) { 1373 console.error('on accountChange failed, error:' + JSON.stringify(err)); 1374 } 1375 ``` 1376 1377### off('accountChange')<sup>9+</sup> 1378 1379off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void 1380 1381Unsubscribes from account information changes. 1382 1383**System capability**: SystemCapability.Account.AppAccount 1384 1385**Parameters** 1386 1387| Name | Type | Mandatory | Description | 1388| -------- | -------------------------------- | ---- | ------------ | 1389| type | 'accountChange' | Yes | Event type to unsubscribe from. The value is **'accountChange'**. | 1390| 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. | 1391 1392**Error codes** 1393 1394| ID | Error Message| 1395| ------- | -------| 1396| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1397| 12300001 | System service exception. | 1398| 12300002 | Invalid type. | 1399 1400**Example** 1401 1402 ```ts 1403 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 1404 console.log('receive change data:' + JSON.stringify(data)); 1405 } 1406 try{ 1407 appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback); 1408 } catch(err) { 1409 console.error('on accountChange failed, error:' + JSON.stringify(err)); 1410 } 1411 try{ 1412 appAccountManager.off('accountChange', changeOnCallback); 1413 } 1414 catch(err){ 1415 console.error('off accountChange failed, error:' + JSON.stringify(err)); 1416 } 1417 ``` 1418 1419### auth<sup>9+</sup> 1420 1421auth(name: string, owner: string, authType: string, callback: AuthCallback): void 1422 1423Authenticates an app account. This API uses an asynchronous callback to return the result. 1424 1425**System capability**: SystemCapability.Account.AppAccount 1426 1427**Parameters** 1428 1429| Name | Type | Mandatory | Description | 1430| -------- | --------------------- | ---- | --------------- | 1431| name | string | Yes | Name of the target app account. | 1432| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1433| authType | string | Yes | Authentication type. | 1434| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the authentication result. | 1435 1436**Error codes** 1437 1438| ID | Error Message| 1439| ------- | -------| 1440| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1441| 12300001 | System service exception. | 1442| 12300002 | Invalid name, owner or authType. | 1443| 12300003 | Account not found. | 1444| 12300010 | Account service busy. | 1445| 12300113 | Authenticator service not found. | 1446| 12300114 | Authenticator service exception. | 1447 1448**Example** 1449 1450 ```ts 1451 import { BusinessError } from '@kit.BasicServicesKit'; 1452 import { Want, common } from '@kit.AbilityKit'; 1453 1454 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 1455 1456 function onResultCallback(code: number, authResult?: appAccount.AuthResult): void { 1457 console.log('resultCode: ' + code); 1458 console.log('authResult: ' + JSON.stringify(authResult)); 1459 } 1460 1461 function onRequestRedirectedCallback(request: Want): void { 1462 let wantInfo: Want = { 1463 deviceId: '', 1464 bundleName: 'com.example.accountjsdemo', 1465 action: 'ohos.want.action.viewData', 1466 entities: ['entity.system.default'], 1467 } 1468 context.startAbility(wantInfo).then(() => { 1469 console.log('startAbility successfully'); 1470 }).catch((err: BusinessError) => { 1471 console.log('startAbility err: ' + JSON.stringify(err)); 1472 }) 1473 } 1474 1475 try { 1476 appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', { 1477 onResult: onResultCallback, 1478 onRequestRedirected: onRequestRedirectedCallback 1479 }); 1480 } catch (err) { 1481 console.log('auth exception: ' + JSON.stringify(err)); 1482 } 1483 ``` 1484 1485### auth<sup>9+</sup> 1486 1487auth(name: string, owner: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void 1488 1489Authenticates an app account. This API uses an asynchronous callback to return the result. 1490 1491**System capability**: SystemCapability.Account.AppAccount 1492 1493**Parameters** 1494 1495| Name | Type | Mandatory | Description | 1496| -------- | --------------------- | ---- | --------------- | 1497| name | string | Yes | Name of the target app account. | 1498| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1499| authType | string | Yes | Authentication type. | 1500| options | Record<string, Object> | Yes | Options for the authentication. | 1501| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the authentication result. | 1502 1503**Error codes** 1504 1505| ID | Error Message| 1506| ------- | -------| 1507| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1508| 12300001 | System service exception. | 1509| 12300002 | Invalid name, owner, authType or options. | 1510| 12300003 | Account not found. | 1511| 12300010 | Account service busy. | 1512| 12300113 | Authenticator service not found. | 1513| 12300114 | Authenticator service exception. | 1514 1515**Example** 1516 1517 ```ts 1518 import { BusinessError } from '@kit.BasicServicesKit'; 1519 import { Want, common } from '@kit.AbilityKit'; 1520 1521 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 1522 1523 function onResultCallback(code: number, authResult?: appAccount.AuthResult): void { 1524 console.log('resultCode: ' + code); 1525 console.log('authResult: ' + JSON.stringify(authResult)); 1526 } 1527 1528 function onRequestRedirectedCallback(request: Want): void { 1529 let wantInfo: Want = { 1530 deviceId: '', 1531 bundleName: 'com.example.accountjsdemo', 1532 action: 'ohos.want.action.viewData', 1533 entities: ['entity.system.default'], 1534 } 1535 context.startAbility(wantInfo).then(() => { 1536 console.log('startAbility successfully'); 1537 }).catch((err: BusinessError) => { 1538 console.log('startAbility err: ' + JSON.stringify(err)); 1539 }) 1540 } 1541 1542 let options: Record<string, Object> = { 1543 'password': 'xxxx', 1544 }; 1545 try { 1546 appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, { 1547 onResult: onResultCallback, 1548 onRequestRedirected: onRequestRedirectedCallback 1549 }); 1550 } catch (err) { 1551 console.log('auth exception: ' + JSON.stringify(err)); 1552 } 1553 ``` 1554 1555### getAuthToken<sup>9+</sup> 1556 1557getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 1558 1559Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 1560 1561**System capability**: SystemCapability.Account.AppAccount 1562 1563**Parameters** 1564 1565| Name | Type | Mandatory | Description | 1566| -------- | --------------------------- | ---- | ----------- | 1567| name | string | Yes | Name of the target app account. | 1568| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1569| authType | string | Yes | Authentication type. | 1570| 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. | 1571 1572**Error codes** 1573 1574| ID | Error Message| 1575| ------- | -------| 1576| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1577| 12300001 | System service exception. | 1578| 12300002 | Invalid name, owner or authType. | 1579| 12300003 | Account not found. | 1580| 12300107 | AuthType not found. | 1581 1582**Example** 1583 1584 ```ts 1585 import { BusinessError } from '@kit.BasicServicesKit'; 1586 1587 try { 1588 appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 1589 (err: BusinessError, token: string) => { 1590 if (err) { 1591 console.log('getAuthToken failed, error: ' + JSON.stringify(err)); 1592 } else { 1593 console.log('getAuthToken successfully, token: ' + token); 1594 } 1595 }); 1596 } catch (err) { 1597 console.log('getAuthToken exception: ' + JSON.stringify(err)); 1598 } 1599 ``` 1600 1601### getAuthToken<sup>9+</sup> 1602 1603getAuthToken(name: string, owner: string, authType: string): Promise<string> 1604 1605Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 1606 1607**System capability**: SystemCapability.Account.AppAccount 1608 1609**Parameters** 1610 1611| Name | Type | Mandatory | Description | 1612| -------- | ------ | ---- | ----------- | 1613| name | string | Yes | Name of the target app account. | 1614| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1615| authType | string | Yes | Authentication type. | 1616 1617**Return value** 1618 1619| Type | Description | 1620| --------------------- | --------------------- | 1621| Promise<string> | Promise used to return the authorization token obtained. | 1622 1623**Error codes** 1624 1625| ID | Error Message | 1626| ------- | ------- | 1627| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1628| 12300001 | System service exception. | 1629| 12300002 | Invalid name, owner or authType. | 1630| 12300003 | Account not found. | 1631| 12300107 | AuthType not found. | 1632 1633**Example** 1634 1635 ```ts 1636 import { BusinessError } from '@kit.BasicServicesKit'; 1637 1638 try { 1639 appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token: string) => { 1640 console.log('getAuthToken successfully, token: ' + token); 1641 }).catch((err: BusinessError) => { 1642 console.log('getAuthToken failed, error: ' + JSON.stringify(err)); 1643 }); 1644 } catch (err) { 1645 console.log('getAuthToken exception: ' + JSON.stringify(err)); 1646 } 1647 ``` 1648 1649### setAuthToken<sup>9+</sup> 1650 1651setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 1652 1653Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. 1654 1655**System capability**: SystemCapability.Account.AppAccount 1656 1657**Parameters** 1658 1659| Name | Type | Mandatory | Description | 1660| -------- | ------------------------- | ---- | -------- | 1661| name | string | Yes | Name of the target app account. | 1662| authType | string | Yes | Authentication type. | 1663| token | string | Yes | Authorization token to set. | 1664| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1665 1666**Error codes** 1667 1668| ID | Error Message| 1669| ------- | -------| 1670| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1671| 12300001 | System service exception. | 1672| 12300002 | Invalid name, authType or token. | 1673| 12300003 | Account not found. | 1674| 12400004 | The number of tokens reaches the upper limit. | 1675 1676**Example** 1677 1678 ```ts 1679 import { BusinessError } from '@kit.BasicServicesKit'; 1680 1681 try { 1682 appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => { 1683 if (err) { 1684 console.log('setAuthToken failed, error: ' + JSON.stringify(err)); 1685 } else { 1686 console.log('setAuthToken successfully'); 1687 } 1688 }); 1689 } catch (err) { 1690 console.log('setAuthToken exception: ' + JSON.stringify(err)); 1691 } 1692 ``` 1693 1694### setAuthToken<sup>9+</sup> 1695 1696setAuthToken(name: string, authType: string, token: string): Promise<void> 1697 1698Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. 1699 1700**System capability**: SystemCapability.Account.AppAccount 1701 1702**Parameters** 1703 1704| Name | Type | Mandatory | Description | 1705| -------- | ------ | ---- | -------- | 1706| name | string | Yes | Name of the target app account. | 1707| authType | string | Yes | Authentication type. | 1708| token | string | Yes | Authorization token to set. | 1709 1710**Return value** 1711 1712| Type | Description | 1713| ------------------- | --------------------- | 1714| Promise<void> | Promise that returns no value. | 1715 1716**Error codes** 1717 1718| ID | Error Message| 1719| ------- | -------| 1720| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1721| 12300001 | System service exception. | 1722| 12300002 | Invalid name, authType or token. | 1723| 12300003 | Account not found. | 1724| 12400004 | The number of tokens reaches the upper limit. | 1725 1726**Example** 1727 1728 ```ts 1729 import { BusinessError } from '@kit.BasicServicesKit'; 1730 1731 try { 1732 appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { 1733 console.log('setAuthToken successfully'); 1734 }).catch((err: BusinessError) => { 1735 console.log('setAuthToken failed, error: ' + JSON.stringify(err)); 1736 }); 1737 } catch (err) { 1738 console.log('setAuthToken exception: ' + JSON.stringify(err)); 1739 } 1740 ``` 1741 1742### deleteAuthToken<sup>9+</sup> 1743 1744deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 1745 1746Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 1747 1748**System capability**: SystemCapability.Account.AppAccount 1749 1750**Parameters** 1751 1752| Name | Type | Mandatory | Description | 1753| -------- | ------------------------- | ---- | ------------ | 1754| name | string | Yes | Name of the target app account. | 1755| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1756| authType | string | Yes | Authentication type. | 1757| token | string | Yes | Authorization token to delete.| 1758| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1759 1760**Error codes** 1761 1762| ID | Error Message | 1763| ------- | ------- | 1764| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1765| 12300001 | System service exception. | 1766| 12300002 | Invalid name, owner, authType or token. | 1767| 12300003 | Account not found. | 1768| 12300107 | AuthType not found. | 1769 1770**Example** 1771 1772 ```ts 1773 import { BusinessError } from '@kit.BasicServicesKit'; 1774 1775 try { 1776 appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', 1777 (err: BusinessError) => { 1778 if (err) { 1779 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1780 } else { 1781 console.log('deleteAuthToken successfully'); 1782 } 1783 }); 1784 } catch (err) { 1785 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1786 } 1787 ``` 1788 1789### deleteAuthToken<sup>9+</sup> 1790 1791deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 1792 1793Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 1794 1795**System capability**: SystemCapability.Account.AppAccount 1796 1797**Parameters** 1798 1799| Name | Type | Mandatory | Description | 1800| -------- | ------ | ---- | ------------ | 1801| name | string | Yes | Name of the target app account. | 1802| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1803| authType | string | Yes | Authentication type. | 1804| token | string | Yes | Authorization token to delete.| 1805 1806**Return value** 1807 1808| Type | Description | 1809| ------------------- | --------------------- | 1810| Promise<void> | Promise that returns no value. | 1811 1812**Error codes** 1813 1814| ID | Error Message | 1815| ------- | ------- | 1816| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1817| 12300001 | System service exception. | 1818| 12300002 | Invalid name, owner, authType or token. | 1819| 12300003 | Account not found. | 1820| 12300107 | AuthType not found. | 1821 1822**Example** 1823 1824 ```ts 1825 import { BusinessError } from '@kit.BasicServicesKit'; 1826 1827 try { 1828 appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { 1829 console.log('deleteAuthToken successfully'); 1830 }).catch((err: BusinessError) => { 1831 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1832 }); 1833 } catch (err) { 1834 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1835 } 1836 ``` 1837 1838### setAuthTokenVisibility<sup>9+</sup> 1839 1840setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 1841 1842Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. 1843 1844**System capability**: SystemCapability.Account.AppAccount 1845 1846**Parameters** 1847 1848| Name | Type | Mandatory | Description | 1849| ---------- | ------------------------- | ---- | ------------------------- | 1850| name | string | Yes | Name of the target app account. | 1851| authType | string | Yes | Authentication type. | 1852| bundleName | string | Yes | Bundle name of the app. | 1853| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 1854| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1855 1856**Error codes** 1857 1858| ID | Error Message| 1859| ------- | -------| 1860| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1861| 12300001 | System service exception. | 1862| 12300002 | Invalid name, authType or bundleName. | 1863| 12300003 | Account not found. | 1864| 12300107 | AuthType not found. | 1865| 12400001 | Application not found. | 1866| 12400005 | The size of authorization list reaches the upper limit. | 1867 1868**Example** 1869 1870 ```ts 1871 import { BusinessError } from '@kit.BasicServicesKit'; 1872 1873 try { 1874 appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, 1875 (err: BusinessError) => { 1876 if (err) { 1877 console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1878 } else { 1879 console.log('setAuthTokenVisibility successfully'); 1880 } 1881 }); 1882 } catch (err) { 1883 console.log('setAuthTokenVisibility exception: ' + JSON.stringify(err)); 1884 } 1885 ``` 1886 1887### setAuthTokenVisibility<sup>9+</sup> 1888 1889setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 1890 1891Sets the visibility of an authorization token to an app. This API uses a promise to return the result. 1892 1893**System capability**: SystemCapability.Account.AppAccount 1894 1895**Parameters** 1896 1897| Name | Type | Mandatory | Description | 1898| ---------- | ------------------------- | ---- | ------------------------- | 1899| name | string | Yes | Name of the target app account. | 1900| authType | string | Yes | Authentication type. | 1901| bundleName | string | Yes | Bundle name of the app. | 1902| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 1903 1904**Return value** 1905 1906| Type | Description | 1907| ------------------- | --------------------- | 1908| Promise<void> | Promise that returns no value. | 1909 1910**Error codes** 1911 1912| ID | Error Message| 1913| ------- | -------| 1914| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1915| 12300001 | System service exception. | 1916| 12300002 | Invalid name, authType or bundleName. | 1917| 12300003 | Account not found. | 1918| 12300107 | AuthType not found. | 1919| 12400001 | Application not found. | 1920| 12400005 | The size of authorization list reaches the upper limit. | 1921 1922**Example** 1923 1924 ```ts 1925 import { BusinessError } from '@kit.BasicServicesKit'; 1926 1927 try { 1928 appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { 1929 console.log('setAuthTokenVisibility successfully'); 1930 }).catch((err: BusinessError) => { 1931 console.log('setAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1932 }); 1933 } catch (err) { 1934 console.log('setAuthTokenVisibility exception: ' + JSON.stringify(err)); 1935 } 1936 ``` 1937 1938### checkAuthTokenVisibility<sup>9+</sup> 1939 1940checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 1941 1942Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. 1943 1944**System capability**: SystemCapability.Account.AppAccount 1945 1946**Parameters** 1947 1948| Name | Type | Mandatory | Description | 1949| ---------- | ---------------------------- | ---- | ----------- | 1950| name | string | Yes | Name of the target app account. | 1951| authType | string | Yes | Authentication type. | 1952| bundleName | string | Yes | Bundle name of the app. | 1953| 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 app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | 1954 1955**Error codes** 1956 1957| ID | Error Message| 1958| ------- | -------| 1959| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1960| 12300001 | System service exception. | 1961| 12300002 | Invalid name, authType or bundleName. | 1962| 12300003 | Account not found. | 1963| 12300107 | AuthType not found. | 1964 1965**Example** 1966 1967 ```ts 1968 import { BusinessError } from '@kit.BasicServicesKit'; 1969 1970 try { 1971 appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', 1972 (err: BusinessError, isVisible: boolean) => { 1973 if (err) { 1974 console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 1975 } else { 1976 console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); 1977 } 1978 }); 1979 } catch (err) { 1980 console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err)); 1981 } 1982 ``` 1983 1984### checkAuthTokenVisibility<sup>9+</sup> 1985 1986checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 1987 1988Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. 1989 1990**System capability**: SystemCapability.Account.AppAccount 1991 1992**Parameters** 1993 1994| Name | Type | Mandatory | Description | 1995| ---------- | ------ | ---- | ------------- | 1996| name | string | Yes | Name of the target app account. | 1997| authType | string | Yes | Authentication type. | 1998| bundleName | string | Yes | Bundle name of the app. | 1999 2000**Return value** 2001 2002| Type | Description | 2003| ---------------------- | --------------------- | 2004| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 2005 2006**Error codes** 2007 2008| ID | Error Message| 2009| ------- | -------| 2010| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2011| 12300001 | System service exception. | 2012| 12300002 | Invalid name, authType or bundleName. | 2013| 12300003 | Account not found. | 2014| 12300107 | AuthType not found. | 2015 2016**Example** 2017 2018 ```ts 2019 import { BusinessError } from '@kit.BasicServicesKit'; 2020 2021 try { 2022 appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then(( 2023 isVisible: boolean) => { 2024 console.log('checkAuthTokenVisibility successfully, isVisible: ' + isVisible); 2025 }).catch((err: BusinessError) => { 2026 console.log('checkAuthTokenVisibility failed, error: ' + JSON.stringify(err)); 2027 }); 2028 } catch (err) { 2029 console.log('checkAuthTokenVisibility exception: ' + JSON.stringify(err)); 2030 } 2031 ``` 2032 2033### getAllAuthTokens<sup>9+</sup> 2034 2035getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void 2036 2037Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. 2038 2039**System capability**: SystemCapability.Account.AppAccount 2040 2041**Parameters** 2042 2043| Name | Type | Mandatory | Description | 2044| -------- | ---------------------------------------- | ---- | ----------- | 2045| name | string | Yes | Name of the target app account. | 2046| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2047| 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. | 2048 2049**Error codes** 2050 2051| ID | Error Message| 2052| ------- | -------| 2053| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2054| 12300001 | System service exception. | 2055| 12300002 | Invalid name or owner. | 2056| 12300003 | Account not found. | 2057 2058**Example** 2059 2060 ```ts 2061 import { BusinessError } from '@kit.BasicServicesKit'; 2062 2063 try { 2064 appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo', 2065 (err: BusinessError, tokenArr: appAccount.AuthTokenInfo[]) => { 2066 if (err) { 2067 console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); 2068 } else { 2069 console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr); 2070 } 2071 }); 2072 } catch (err) { 2073 console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); 2074 } 2075 ``` 2076 2077### getAllAuthTokens<sup>9+</sup> 2078 2079getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>> 2080 2081Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. 2082 2083**System capability**: SystemCapability.Account.AppAccount 2084 2085**Parameters** 2086 2087| Name | Type | Mandatory | Description | 2088| ----- | ------ | ---- | ----------- | 2089| name | string | Yes | Name of the target app account. | 2090| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2091 2092**Return value** 2093 2094| Type | Description | 2095| ---------------------------------------- | --------------------- | 2096| Promise<Array<[AuthTokenInfo](#authtokeninfo9)>> | Promise used to return the tokens obtained. | 2097 2098**Error codes** 2099 2100| ID | Error Message| 2101| ------- | -------| 2102| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2103| 12300001 | System service exception. | 2104| 12300002 | Invalid name or owner. | 2105| 12300003 | Account not found. | 2106 2107**Example** 2108 2109 ```ts 2110 import { BusinessError } from '@kit.BasicServicesKit'; 2111 2112 try { 2113 appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then(( 2114 tokenArr: appAccount.AuthTokenInfo[]) => { 2115 console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr)); 2116 }).catch((err: BusinessError) => { 2117 console.log('getAllAuthTokens failed, error: ' + JSON.stringify(err)); 2118 }); 2119 } catch (err) { 2120 console.log('getAllAuthTokens exception: ' + JSON.stringify(err)); 2121 } 2122 ``` 2123 2124### getAuthList<sup>9+</sup> 2125 2126getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 2127 2128Obtains the authorization list of the specified authentication type for an app 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. 2129 2130**System capability**: SystemCapability.Account.AppAccount 2131 2132**Parameters** 2133 2134| Name | Type | Mandatory | Description | 2135| -------- | ---------------------------------------- | ---- | ----------------------- | 2136| name | string | Yes | Name of the target app account. | 2137| authType | string | Yes | Authentication type. | 2138| 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. | 2139 2140**Error codes** 2141 2142| ID | Error Message| 2143| ------- | -------| 2144| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2145| 12300001 | System service exception. | 2146| 12300002 | Invalid name or authType. | 2147| 12300003 | Account not found. | 2148| 12300107 | AuthType not found. | 2149 2150**Example** 2151 2152 ```ts 2153 import { BusinessError } from '@kit.BasicServicesKit'; 2154 2155 try { 2156 appAccountManager.getAuthList('LiSi', 'getSocialData', (err: BusinessError, authList: string[]) => { 2157 if (err) { 2158 console.log('getAuthList failed, error: ' + JSON.stringify(err)); 2159 } else { 2160 console.log('getAuthList successfully, authList: ' + authList); 2161 } 2162 }); 2163 } catch (err) { 2164 console.log('getAuthList exception: ' + JSON.stringify(err)); 2165 } 2166 ``` 2167 2168### getAuthList<sup>9+</sup> 2169 2170getAuthList(name: string, authType: string): Promise<Array<string>> 2171 2172Obtains the authorization list of the specified authentication type for an app 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. 2173 2174**System capability**: SystemCapability.Account.AppAccount 2175 2176**Parameters** 2177 2178| Name | Type | Mandatory | Description | 2179| -------- | ------ | ---- | ------------------------------ | 2180| name | string | Yes | Name of the target app account. | 2181| authType | string | Yes | Authentication type. | 2182 2183**Return value** 2184 2185| Type | Description | 2186| ---------------------------------- | --------------------- | 2187| Promise<Array<string>> | Promise used to return a list of authorized bundles. | 2188 2189**Error codes** 2190 2191| ID | Error Message| 2192| ------- | -------| 2193| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2194| 12300001 | System service exception. | 2195| 12300002 | Invalid name or authType. | 2196| 12300003 | Account not found. | 2197| 12300107 | AuthType not found. | 2198 2199**Example** 2200 2201 ```ts 2202 import { BusinessError } from '@kit.BasicServicesKit'; 2203 2204 try { 2205 appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList: string[]) => { 2206 console.log('getAuthList successfully, authList: ' + authList); 2207 }).catch((err: BusinessError) => { 2208 console.log('getAuthList failed, error: ' + JSON.stringify(err)); 2209 }); 2210 } catch (err) { 2211 console.log('getAuthList exception: ' + JSON.stringify(err)); 2212 } 2213 ``` 2214 2215### getAuthCallback<sup>9+</sup> 2216 2217getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void 2218 2219Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. 2220 2221**System capability**: SystemCapability.Account.AppAccount 2222 2223**Parameters** 2224 2225| Name | Type | Mandatory | Description | 2226| --------- | ---------------------------------------- | ---- | -------- | 2227| sessionId | string | Yes | ID of the authentication session. | 2228| 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. | 2229 2230**Error codes** 2231 2232| ID | Error Message | 2233| ------- | ------- | 2234| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2235| 12300001 | System service exception. | 2236| 12300002 | Invalid sessionId. | 2237| 12300108 | Session not found. | 2238 2239**Example** 2240 2241 ```ts 2242 import { BusinessError } from '@kit.BasicServicesKit'; 2243 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 2244 2245 export default class EntryAbility extends UIAbility { 2246 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 2247 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 2248 try { 2249 appAccountManager.getAuthCallback(sessionId, (err: BusinessError, callback: appAccount.AuthCallback) => { 2250 if (err != null) { 2251 console.log('getAuthCallback err: ' + JSON.stringify(err)); 2252 return; 2253 } 2254 let result: appAccount.AuthResult = { 2255 account: { 2256 name: 'Lisi', 2257 owner: 'com.example.accountjsdemo', 2258 }, 2259 tokenInfo: { 2260 token: 'xxxxxx', 2261 authType: 'getSocialData' 2262 } 2263 }; 2264 callback.onResult(0, result); 2265 }); 2266 } catch (err) { 2267 console.log('getAuthCallback exception: ' + JSON.stringify(err)); 2268 } 2269 } 2270 } 2271 ``` 2272 2273### getAuthCallback<sup>9+</sup> 2274 2275getAuthCallback(sessionId: string): Promise<AuthCallback> 2276 2277Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. 2278 2279**System capability**: SystemCapability.Account.AppAccount 2280 2281**Parameters** 2282 2283| Name | Type | Mandatory | Description | 2284| --------- | ------ | ---- | -------- | 2285| sessionId | string | Yes | ID of the authentication session. | 2286 2287**Return value** 2288 2289| Type | Description | 2290| ------------------------------------ | --------------------- | 2291| Promise<[AuthCallback](#authcallback9)> | Promise used to return the authenticator callback obtained. | 2292 2293**Error codes** 2294 2295| ID | Error Message | 2296| ------- | ------- | 2297| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2298| 12300001 | System service exception. | 2299| 12300002 | Invalid sessionId. | 2300| 12300108 | Session not found. | 2301 2302**Example** 2303 2304 ```ts 2305 import { BusinessError } from '@kit.BasicServicesKit'; 2306 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 2307 2308 export default class EntryAbility extends UIAbility { 2309 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 2310 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 2311 try { 2312 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 2313 let result: appAccount.AuthResult = { 2314 account: { 2315 name: 'Lisi', 2316 owner: 'com.example.accountjsdemo', 2317 }, 2318 tokenInfo: { 2319 token: 'xxxxxx', 2320 authType: 'getSocialData' 2321 } 2322 }; 2323 callback.onResult(0, result); 2324 }).catch((err: BusinessError) => { 2325 console.log('getAuthCallback err: ' + JSON.stringify(err)); 2326 }); 2327 } catch (err) { 2328 console.log('getAuthCallback exception: ' + JSON.stringify(err)); 2329 } 2330 } 2331 } 2332 ``` 2333 2334### queryAuthenticatorInfo<sup>9+</sup> 2335 2336queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 2337 2338Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. 2339 2340**System capability**: SystemCapability.Account.AppAccount 2341 2342**Parameters** 2343 2344| Name | Type | Mandatory | Description | 2345| -------- | -------------------------------------- | ---- | ----------- | 2346| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2347| 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. | 2348 2349**Error codes** 2350 2351| ID | Error Message| 2352| ------- | -------| 2353| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2354| 12300001 | System service exception. | 2355| 12300002 | Invalid owner. | 2356| 12300113 | Authenticator service not found. | 2357 2358**Example** 2359 2360 ```ts 2361 import { BusinessError } from '@kit.BasicServicesKit'; 2362 2363 try { 2364 appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo', 2365 (err: BusinessError, info: appAccount.AuthenticatorInfo) => { 2366 if (err) { 2367 console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); 2368 } else { 2369 console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); 2370 } 2371 }); 2372 } catch (err) { 2373 console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); 2374 } 2375 ``` 2376 2377### queryAuthenticatorInfo<sup>9+</sup> 2378 2379queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 2380 2381Obtains the authenticator information of an app. This API uses a promise to return the result. 2382 2383**System capability**: SystemCapability.Account.AppAccount 2384 2385**Parameters** 2386 2387| Name | Type | Mandatory | Description | 2388| ----- | ------ | ---- | ----------- | 2389| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2390 2391**Return value** 2392 2393| Type | Description | 2394| -------------------------------- | --------------------- | 2395| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained. | 2396 2397**Error codes** 2398 2399| ID | Error Message| 2400| ------- | -------| 2401| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2402| 12300001 | System service exception. | 2403| 12300002 | Invalid owner. | 2404| 12300113 | Authenticator service not found. | 2405 2406**Example** 2407 2408 ```ts 2409 import { BusinessError } from '@kit.BasicServicesKit'; 2410 2411 try { 2412 appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then(( 2413 info: appAccount.AuthenticatorInfo) => { 2414 console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); 2415 }).catch((err: BusinessError) => { 2416 console.log('queryAuthenticatorInfo failed, error: ' + JSON.stringify(err)); 2417 }); 2418 } catch (err) { 2419 console.log('queryAuthenticatorInfo exception: ' + JSON.stringify(err)); 2420 } 2421 ``` 2422 2423### checkAccountLabels<sup>9+</sup> 2424 2425checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void 2426 2427Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target app. 2428 2429**System capability**: SystemCapability.Account.AppAccount 2430 2431**Parameters** 2432 2433| Name | Type | Mandatory | Description | 2434| -------------- | ------------------------- | ----- | --------------- | 2435| name | string | Yes | Name of the target app account. | 2436| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 2437| labels | Array<string> | Yes | Labels to check. | 2438| 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 app account has the labels; the value **false** means the opposite. If the operation fails, **err** is an error object. | 2439 2440**Error codes** 2441 2442| ID | Error Message | 2443| ------- | ------- | 2444| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2445| 12300001 | System service exception. | 2446| 12300002 | Invalid name, owner or labels. | 2447| 12300003 | Account not found. | 2448| 12300010 | Account service busy. | 2449| 12300113 | Authenticator service not found. | 2450| 12300114 | Authenticator service exception. | 2451 2452**Example** 2453 2454 ```ts 2455 import { BusinessError } from '@kit.BasicServicesKit'; 2456 2457 let labels = ['student']; 2458 try { 2459 appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels, 2460 (err: BusinessError, hasAllLabels: boolean) => { 2461 if (err) { 2462 console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); 2463 } else { 2464 console.log('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels); 2465 } 2466 }); 2467 } catch (err) { 2468 console.log('checkAccountLabels exception: ' + JSON.stringify(err)); 2469 } 2470 ``` 2471 2472### checkAccountLabels<sup>9+</sup> 2473 2474checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean> 2475 2476Checks whether an app account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target app. 2477 2478**System capability**: SystemCapability.Account.AppAccount 2479 2480**Parameters** 2481 2482| Name | Type | Mandatory | Description | 2483| -------------- | ------------------------- | ----- | --------------- | 2484| name | string | Yes | Name of the target app account. | 2485| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 2486| labels | Array<string> | Yes | Labels to check. | 2487 2488**Return value** 2489 2490| Type | Description | 2491| ------------------- | -------------------------------- | 2492| Promise<boolean> | Promise used to return the result. The value **true** means the app account has the labels; the value **false** means the opposite. | 2493 2494**Error codes** 2495 2496| ID | Error Message | 2497| ------- | ------- | 2498| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2499| 12300001 | System service exception. | 2500| 12300002 | Invalid name, owner or labels. | 2501| 12300003 | Account not found. | 2502| 12300010 | Account service busy. | 2503| 12300113 | Authenticator service not found. | 2504| 12300114 | Authenticator service exception. | 2505 2506**Example** 2507 2508 ```ts 2509 import { BusinessError } from '@kit.BasicServicesKit'; 2510 2511 let labels = ['student']; 2512 try { 2513 appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then(( 2514 hasAllLabels: boolean) => { 2515 console.log('checkAccountLabels successfully: ' + hasAllLabels); 2516 }).catch((err: BusinessError) => { 2517 console.log('checkAccountLabels failed, error: ' + JSON.stringify(err)); 2518 }); 2519 } catch (err) { 2520 console.log('checkAccountLabels exception: ' + JSON.stringify(err)); 2521 } 2522 ``` 2523 2524### deleteCredential<sup>9+</sup> 2525 2526deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void 2527 2528Deletes the credential of the specified type from an app account. This API uses an asynchronous callback to return the result. 2529 2530**System capability**: SystemCapability.Account.AppAccount 2531 2532**Parameters** 2533 2534| Name | Type | Mandatory | Description | 2535| -------------- | ------------------------- | ----- | -------------- | 2536| name | string | Yes | Name of the target app account. | 2537| credentialType | string | Yes | Type of the credential to delete. | 2538| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 2539 2540**Error codes** 2541 2542| ID | Error Message | 2543| ------- | ------- | 2544| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2545| 12300001 | System service exception. | 2546| 12300002 | Invalid name or credentialType. | 2547| 12300003 | Account not found. | 2548| 12300102 | Credential not found. | 2549 2550**Example** 2551 2552 ```ts 2553 import { BusinessError } from '@kit.BasicServicesKit'; 2554 2555 try { 2556 appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err: BusinessError) => { 2557 if (err) { 2558 console.log('deleteCredential failed, error: ' + JSON.stringify(err)); 2559 } else { 2560 console.log('deleteCredential successfully'); 2561 } 2562 }); 2563 } catch (err) { 2564 console.log('deleteCredential exception: ' + JSON.stringify(err)); 2565 } 2566 ``` 2567 2568### deleteCredential<sup>9+</sup> 2569 2570deleteCredential(name: string, credentialType: string): Promise<void> 2571 2572Deletes the credential of the specified type from an app account. This API uses a promise to return the result. 2573 2574**System capability**: SystemCapability.Account.AppAccount 2575 2576**Parameters** 2577 2578| Name | Type | Mandatory | Description | 2579| -------------- | ------ | ----- | --------------- | 2580| name | string | Yes | Name of the target app account. | 2581| credentialType | string | Yes | Type of the credential to delete. | 2582 2583**Return value** 2584 2585| Type | Description | 2586| ------------------- | -------------------------------- | 2587| Promise<void> | Promise that returns no value. | 2588 2589**Error codes** 2590 2591| ID | Error Message | 2592| ------- | ------- | 2593| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2594| 12300001 | System service exception. | 2595| 12300002 | Invalid name or credentialType. | 2596| 12300003 | Account not found. | 2597| 12300102 | Credential not found. | 2598 2599**Example** 2600 2601 ```ts 2602 import { BusinessError } from '@kit.BasicServicesKit'; 2603 2604 try { 2605 appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => { 2606 console.log('deleteCredential successfully'); 2607 }).catch((err: BusinessError) => { 2608 console.log('deleteCredential failed, error: ' + JSON.stringify(err)); 2609 }); 2610 } catch (err) { 2611 console.log('deleteCredential exception: ' + JSON.stringify(err)); 2612 } 2613 ``` 2614 2615### selectAccountsByOptions<sup>9+</sup> 2616 2617selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void 2618 2619Selects 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 app provides the capability of checking the labels. 2620 2621**System capability**: SystemCapability.Account.AppAccount 2622 2623**Parameters** 2624 2625| Name | Type | Mandatory | Description | 2626| -------------- | ----------------------------------- | ----- | --------------- | 2627| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | 2628| 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. | 2629 2630**Error codes** 2631 2632| ID | Error Message | 2633| ------- | ------- | 2634| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2635| 12300001 | System service exception. | 2636| 12300002 | Invalid options. | 2637| 12300010 | Account service busy. | 2638| 12300114 | Authenticator service exception. | 2639 2640**Example** 2641 2642 ```ts 2643 import { BusinessError } from '@kit.BasicServicesKit'; 2644 2645 let options: appAccount.SelectAccountsOptions = { 2646 allowedOwners: [ 'com.example.accountjsdemo' ], 2647 requiredLabels: [ 'student' ] 2648 }; 2649 try { 2650 appAccountManager.selectAccountsByOptions(options, 2651 (err: BusinessError, accountArr: appAccount.AppAccountInfo[]) => { 2652 if (err) { 2653 console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); 2654 } else { 2655 console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); 2656 } 2657 }); 2658 } catch (err) { 2659 console.log('selectAccountsByOptions exception: ' + JSON.stringify(err)); 2660 } 2661 ``` 2662 2663### selectAccountsByOptions<sup>9+</sup> 2664 2665selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> 2666 2667Selects 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 app provides the capability of checking the labels. 2668 2669**System capability**: SystemCapability.Account.AppAccount 2670 2671**Parameters** 2672 2673| Name | Type | Mandatory | Description | 2674| -------------- | ------------------------- | ----- | --------------- | 2675| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | 2676 2677**Return value** 2678 2679| Type | Description | 2680| ------------------- | -------------------------------- | 2681| Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the accounts selected. | 2682 2683**Error codes** 2684 2685| ID | Error Message | 2686| ------- | ------- | 2687| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2688| 12300001 | System service exception. | 2689| 12300002 | Invalid options. | 2690| 12300010 | Account service busy. | 2691| 12300114 | Authenticator service exception. | 2692 2693**Example** 2694 2695 ```ts 2696 import { BusinessError } from '@kit.BasicServicesKit'; 2697 2698 let options: appAccount.SelectAccountsOptions = { 2699 allowedOwners: ['com.example.accountjsdemo'] 2700 }; 2701 try { 2702 appAccountManager.selectAccountsByOptions(options).then((accountArr: appAccount.AppAccountInfo[]) => { 2703 console.log('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr)); 2704 }).catch((err: BusinessError) => { 2705 console.log('selectAccountsByOptions failed, error: ' + JSON.stringify(err)); 2706 }); 2707 } catch (err) { 2708 console.log('selectAccountsByOptions exception: ' + JSON.stringify(err)); 2709 } 2710 ``` 2711 2712### verifyCredential<sup>9+</sup> 2713 2714verifyCredential(name: string, owner: string, callback: AuthCallback): void 2715 2716Verifies the credential of an app account. This API uses an asynchronous callback to return the result. 2717 2718**System capability**: SystemCapability.Account.AppAccount 2719 2720**Parameters** 2721 2722| Name | Type | Mandatory | Description | 2723| -------- | --------------------- | ----- | ----------------------- | 2724| name | string | Yes | Name of the target app account. | 2725| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2726| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result. | 2727 2728**Error codes** 2729 2730| ID | Error Message| 2731| ------- | -------| 2732| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2733| 12300001 | System service exception. | 2734| 12300002 | Invalid name or owner. | 2735| 12300003 | Account not found. | 2736| 12300010 | Account service busy. | 2737| 12300113 | Authenticator service not found. | 2738| 12300114 | Authenticator service exception. | 2739 2740**Example** 2741 2742 ```ts 2743 import { Want } from '@kit.AbilityKit'; 2744 2745 try { 2746 appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', { 2747 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2748 console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); 2749 console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); 2750 }, 2751 onRequestRedirected: (request: Want) => { 2752 console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); 2753 } 2754 }); 2755 } catch (err) { 2756 console.log('verifyCredential err: ' + JSON.stringify(err)); 2757 } 2758 ``` 2759 2760### verifyCredential<sup>9+</sup> 2761 2762verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void 2763 2764Verifies the user credential. This API uses an asynchronous callback to return the result. 2765 2766**System capability**: SystemCapability.Account.AppAccount 2767 2768**Parameters** 2769 2770| Name | Type | Mandatory | Description | 2771| -------- | ----------------------- | ----- | ----------------------- | 2772| name | string | Yes | Name of the target app account. | 2773| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2774| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for verifying the user credential. | 2775| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result. | 2776 2777**Error codes** 2778 2779| ID | Error Message| 2780| ------- | -------| 2781| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2782| 12300001 | System service exception. | 2783| 12300002 | Invalid name, owner or options. | 2784| 12300003 | Account not found. | 2785| 12300010 | Account service busy. | 2786| 12300113 | Authenticator service not found. | 2787| 12300114 | Authenticator service exception. | 2788 2789**Example** 2790 2791 ```ts 2792 import { Want } from '@kit.AbilityKit'; 2793 2794 let options: appAccount.VerifyCredentialOptions = { 2795 credentialType: 'pin', 2796 credential: '123456' 2797 }; 2798 try { 2799 appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, { 2800 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2801 console.log('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode)); 2802 console.log('verifyCredential onResult, result: ' + JSON.stringify(result)); 2803 }, 2804 onRequestRedirected: (request: Want) => { 2805 console.log('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request)); 2806 } 2807 }); 2808 } catch (err) { 2809 console.log('verifyCredential err: ' + JSON.stringify(err)); 2810 } 2811 ``` 2812 2813### setAuthenticatorProperties<sup>9+</sup> 2814 2815setAuthenticatorProperties(owner: string, callback: AuthCallback): void 2816 2817Sets the authenticator attributes of an app. This API uses an asynchronous callback to return the result. 2818 2819**System capability**: SystemCapability.Account.AppAccount 2820 2821**Parameters** 2822 2823| Name | Type | Mandatory | Description | 2824| -------- | --------------------- | ----- | ----------------------- | 2825| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the app. | 2826| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result. | 2827 2828**Error codes** 2829 2830| ID | Error Message | 2831| ------- | ------- | 2832| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2833| 12300001 | System service exception. | 2834| 12300002 | Invalid owner. | 2835| 12300010 | Account service busy. | 2836| 12300113 | Authenticator service not found. | 2837| 12300114 | Authenticator service exception. | 2838 2839**Example** 2840 2841 ```ts 2842 import { Want } from '@kit.AbilityKit'; 2843 2844 try { 2845 appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', { 2846 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2847 console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); 2848 console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); 2849 }, 2850 onRequestRedirected: (request: Want) => { 2851 console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); 2852 } 2853 }); 2854 } catch (err) { 2855 console.log('setAuthenticatorProperties err: ' + JSON.stringify(err)); 2856 } 2857 ``` 2858 2859### setAuthenticatorProperties<sup>9+</sup> 2860 2861setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void 2862 2863Set authenticator properties. This API uses an asynchronous callback to return the result. 2864 2865**System capability**: SystemCapability.Account.AppAccount 2866 2867**Parameters** 2868 2869| Name | Type | Mandatory | Description | 2870| -------- | --------------------- | ----- | ----------------------- | 2871| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the app. | 2872| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 2873| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 2874 2875**Error codes** 2876 2877| ID | Error Message | 2878| ------- | ------- | 2879| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2880| 12300001 | System service exception. | 2881| 12300002 | Invalid owner or options. | 2882| 12300010 | Account service busy. | 2883| 12300113 | Authenticator service not found. | 2884| 12300114 | Authenticator service exception. | 2885 2886**Example** 2887 2888 ```ts 2889 import { Want } from '@kit.AbilityKit'; 2890 2891 let options: appAccount.SetPropertiesOptions = { 2892 properties: {prop1: 'value1'} 2893 }; 2894 try { 2895 appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, { 2896 onResult: (resultCode: number, result?: appAccount.AuthResult) => { 2897 console.log('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode)); 2898 console.log('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result)); 2899 }, 2900 onRequestRedirected: (request: Want) => { 2901 console.log('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request)); 2902 } 2903 }); 2904 } catch (err) { 2905 console.log('setAuthenticatorProperties err: ' + JSON.stringify(err)); 2906 } 2907 2908 ``` 2909 2910### addAccount<sup>(deprecated)</sup> 2911 2912addAccount(name: string, callback: AsyncCallback<void>): void 2913 2914Adds an app account with the given name. This API uses an asynchronous callback to return the result. 2915 2916> **NOTE** 2917> 2918>This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9) instead. 2919 2920 2921**System capability**: SystemCapability.Account.AppAccount 2922 2923**Parameters** 2924 2925| Name | Type | Mandatory | Description | 2926| -------- | ------------------------- | ---- | -------------------- | 2927| name | string | Yes | Name of the target app account. | 2928| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 2929 2930**Example** 2931 2932 ```ts 2933 import { BusinessError } from '@kit.BasicServicesKit'; 2934 2935 appAccountManager.addAccount('WangWu', (err: BusinessError) => { 2936 console.log('addAccount err: ' + JSON.stringify(err)); 2937 }); 2938 ``` 2939 2940### addAccount<sup>(deprecated)</sup> 2941 2942addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void 2943 2944Adds an app account name and additional information. This API uses an asynchronous callback to return the result. 2945 2946> **NOTE** 2947> This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9-1) instead. 2948 2949**System capability**: SystemCapability.Account.AppAccount 2950 2951**Parameters** 2952 2953| Name | Type | Mandatory | Description | 2954| --------- | ------------------------- | ---- | ---------------------------------------- | 2955| name | string | Yes | Name of the target app account. | 2956| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token. | 2957| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 2958 2959**Example** 2960 2961 ```ts 2962 import { BusinessError } from '@kit.BasicServicesKit'; 2963 2964 appAccountManager.addAccount('LiSi', 'token101', (err: BusinessError) => { 2965 console.log('addAccount err: ' + JSON.stringify(err)); 2966 }); 2967 ``` 2968 2969### addAccount<sup>(deprecated)</sup> 2970 2971addAccount(name: string, extraInfo?: string): Promise<void> 2972 2973Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. 2974 2975> **NOTE** 2976> This API is supported since API version 7 and deprecated since API version 9. Use [createAccount](#createaccount9-2) instead. 2977 2978**System capability**: SystemCapability.Account.AppAccount 2979 2980**Parameters** 2981 2982| Name | Type | Mandatory | Description | 2983| --------- | ------ | ---- | ---------------------------------------- | 2984| name | string | Yes | Name of the target app account. | 2985| 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 app account.<br>By default, no value is passed, which means no additional information needs to be added for the account. | 2986 2987**Return value** 2988 2989| Type | Description | 2990| ------------------- | --------------------- | 2991| Promise<void> | Promise that returns no value. | 2992 2993**Example** 2994 2995 ```ts 2996 import { BusinessError } from '@kit.BasicServicesKit'; 2997 2998 appAccountManager.addAccount('LiSi', 'token101').then(()=> { 2999 console.log('addAccount Success'); 3000 }).catch((err: BusinessError) => { 3001 console.log('addAccount err: ' + JSON.stringify(err)); 3002 }); 3003 ``` 3004 3005### addAccountImplicitly<sup>(deprecated)</sup> 3006 3007addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 3008 3009Adds an app account implicitly based on the specified owner. This API uses an asynchronous callback to return the result. 3010 3011> **NOTE** 3012> 3013> This API is supported since API version 8 and deprecated since API version 9. Use [createAccountImplicitly](#createaccountimplicitly9) instead. 3014 3015**System capability**: SystemCapability.Account.AppAccount 3016 3017**Parameters** 3018 3019| Name | Type | Mandatory | Description | 3020| -------- | --------------------- | ---- | ----------------------- | 3021| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3022| authType | string | Yes | Authentication type. The authentication type is customized. | 3023| options | {[key: string]: any} | Yes | Authentication options, which can be set as required. | 3024| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the result. | 3025 3026**Example** 3027 3028 ```ts 3029 import { BusinessError } from '@kit.BasicServicesKit'; 3030 import { Want, common } from '@kit.AbilityKit'; 3031 3032 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 3033 3034 function onResultCallback(code: number, result: Record<string, Object>): void { 3035 console.log('resultCode: ' + code); 3036 console.log('result: ' + JSON.stringify(result)); 3037 } 3038 3039 function onRequestRedirectedCallback(request: Want): void { 3040 let wantInfo: Want = { 3041 deviceId: '', 3042 bundleName: 'com.example.accountjsdemo', 3043 action: 'ohos.want.action.viewData', 3044 entities: ['entity.system.default'], 3045 } 3046 context.startAbility(wantInfo).then(() => { 3047 console.log('startAbility successfully'); 3048 }).catch((err: BusinessError) => { 3049 console.log('startAbility err: ' + JSON.stringify(err)); 3050 }) 3051 } 3052 3053 appAccountManager.addAccountImplicitly('com.example.accountjsdemo', 'getSocialData', {}, { 3054 onResult: onResultCallback, 3055 onRequestRedirected: onRequestRedirectedCallback 3056 }); 3057 ``` 3058 3059### deleteAccount<sup>(deprecated)</sup> 3060 3061deleteAccount(name: string, callback: AsyncCallback<void>): void 3062 3063Deletes an app account. This API uses an asynchronous callback to return the result. 3064 3065> **NOTE** 3066> 3067> This API is supported since API version 7 and deprecated since API version 9. Use [removeAccount](#removeaccount9) instead. 3068 3069**System capability**: SystemCapability.Account.AppAccount 3070 3071**Parameters** 3072 3073| Name | Type | Mandatory | Description | 3074| -------- | ------------------------- | ---- | ---------------- | 3075| name | string | Yes | Name of the target app account. | 3076| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3077 3078**Example** 3079 3080 ```ts 3081 import { BusinessError } from '@kit.BasicServicesKit'; 3082 3083 appAccountManager.deleteAccount('ZhaoLiu', (err: BusinessError) => { 3084 console.log('deleteAccount err: ' + JSON.stringify(err)); 3085 }); 3086 ``` 3087 3088### deleteAccount<sup>(deprecated)</sup> 3089 3090deleteAccount(name: string): Promise<void> 3091 3092Deletes an app account. This API uses a promise to return the result. 3093 3094> **NOTE** 3095> 3096> This API is supported since API version 7 and deprecated since API version 9. Use [removeAccount](#removeaccount9) instead. 3097 3098**System capability**: SystemCapability.Account.AppAccount 3099 3100**Parameters** 3101 3102| Name | Type | Mandatory | Description | 3103| ---- | ------ | ---- | ----------- | 3104| name | string | Yes | Name of the target app account. | 3105 3106**Return value** 3107 3108| Type | Description | 3109| :------------------ | :-------------------- | 3110| Promise<void> | Promise that returns no value. | 3111 3112**Example** 3113 3114 ```ts 3115 import { BusinessError } from '@kit.BasicServicesKit'; 3116 3117 appAccountManager.deleteAccount('ZhaoLiu').then(() => { 3118 console.log('deleteAccount Success'); 3119 }).catch((err: BusinessError) => { 3120 console.log('deleteAccount err: ' + JSON.stringify(err)); 3121 }); 3122 ``` 3123### disableAppAccess<sup>(deprecated)</sup> 3124 3125disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 3126 3127Disables an app account from accessing an app. This API uses an asynchronous callback to return the result. 3128 3129> **NOTE** 3130> 3131> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9) instead. 3132 3133**System capability**: SystemCapability.Account.AppAccount 3134 3135**Parameters** 3136 3137| Name | Type | Mandatory | Description | 3138| ---------- | ------------------------- | ---- | --------------------------------- | 3139| name | string | Yes | Name of the target app account. | 3140| bundleName | string | Yes | Bundle name of the app. | 3141| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3142 3143**Example** 3144 3145 ```ts 3146 import { BusinessError } from '@kit.BasicServicesKit'; 3147 3148 appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => { 3149 console.log('disableAppAccess err: ' + JSON.stringify(err)); 3150 }); 3151 ``` 3152 3153### disableAppAccess<sup>(deprecated)</sup> 3154 3155disableAppAccess(name: string, bundleName: string): Promise<void> 3156 3157Disables an app account from accessing an app. This API uses a promise to return the result. 3158 3159> **NOTE** 3160> 3161> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9-1) instead. 3162 3163**System capability**: SystemCapability.Account.AppAccount 3164 3165**Parameters** 3166 3167| Name | Type | Mandatory | Description | 3168| ---------- | ------ | ---- | ---------------- | 3169| name | string | Yes | Name of the target app account. | 3170| bundleName | string | Yes | Bundle name of the app. | 3171 3172**Return value** 3173 3174| Type | Description | 3175| :------------------ | :-------------------- | 3176| Promise<void> | Promise that returns no value. | 3177 3178**Example** 3179 3180 ```ts 3181 import { BusinessError } from '@kit.BasicServicesKit'; 3182 3183 appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { 3184 console.log('disableAppAccess Success'); 3185 }).catch((err: BusinessError) => { 3186 console.log('disableAppAccess err: ' + JSON.stringify(err)); 3187 }); 3188 ``` 3189 3190### enableAppAccess<sup>(deprecated)</sup> 3191 3192enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 3193 3194Enables an app account to access an app. This API uses an asynchronous callback to return the result. 3195 3196> **NOTE** 3197> 3198> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9) instead. 3199 3200**System capability**: SystemCapability.Account.AppAccount 3201 3202**Parameters** 3203 3204| Name | Type | Mandatory | Description | 3205| ---------- | ------------------------- | ---- | --------------------------------- | 3206| name | string | Yes | Name of the target app account. | 3207| bundleName | string | Yes | Bundle name of the app. | 3208| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3209 3210**Example** 3211 3212 ```ts 3213 import { BusinessError } from '@kit.BasicServicesKit'; 3214 3215 appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => { 3216 console.log('enableAppAccess: ' + JSON.stringify(err)); 3217 }); 3218 ``` 3219 3220### enableAppAccess<sup>(deprecated)</sup> 3221 3222enableAppAccess(name: string, bundleName: string): Promise<void> 3223 3224Enables an app account to access an app. This API uses a promise to return the result. 3225 3226> **NOTE** 3227> 3228> This API is supported since API version 7 and deprecated since API version 9. Use [setAppAccess](#setappaccess9-1) instead. 3229 3230**System capability**: SystemCapability.Account.AppAccount 3231 3232**Parameters** 3233 3234| Name | Type | Mandatory | Description | 3235| ---------- | ------ | ---- | --------- | 3236| name | string | Yes | Name of the target app account. | 3237| bundleName | string | Yes | Bundle name of the app. | 3238 3239**Return value** 3240 3241| Type | Description | 3242| :------------------ | :-------------------- | 3243| Promise<void> | Promise that returns no value. | 3244 3245**Example** 3246 3247 ```ts 3248 import { BusinessError } from '@kit.BasicServicesKit'; 3249 3250 appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => { 3251 console.log('enableAppAccess Success'); 3252 }).catch((err: BusinessError) => { 3253 console.log('enableAppAccess err: ' + JSON.stringify(err)); 3254 }); 3255 ``` 3256 3257### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3258 3259checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void 3260 3261Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result. 3262 3263> **NOTE** 3264> 3265> This API is supported since API version 7 and deprecated since API version 9. Use [checkDataSyncEnabled](#checkdatasyncenabled9) instead. 3266 3267**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3268 3269**System capability**: SystemCapability.Account.AppAccount 3270 3271**Parameters** 3272 3273| Name | Type | Mandatory | Description | 3274| -------- | ---------------------------- | ---- | --------------------- | 3275| name | string | Yes | Name of the target app account. | 3276| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite. | 3277 3278**Example** 3279 3280 ```ts 3281 import { BusinessError } from '@kit.BasicServicesKit'; 3282 3283 appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err: BusinessError, result: boolean) => { 3284 console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); 3285 console.log('checkAppAccountSyncEnable result: ' + result); 3286 }); 3287 ``` 3288 3289### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3290 3291checkAppAccountSyncEnable(name: string): Promise<boolean> 3292 3293Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result. 3294 3295> **NOTE** 3296> 3297> This API is supported since API version 7 and deprecated since API version 9. Use [checkDataSyncEnabled](#checkdatasyncenabled9-1) instead. 3298 3299**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3300 3301**System capability**: SystemCapability.Account.AppAccount 3302 3303**Parameters** 3304 3305| Name | Type | Mandatory | Description | 3306| ---- | ------ | ---- | ------- | 3307| name | string | Yes | Name of the target app account. | 3308 3309**Return value** 3310 3311| Type | Description | 3312| ---------------------- | --------------------- | 3313| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite. | 3314 3315**Example** 3316 3317 ```ts 3318 import { BusinessError } from '@kit.BasicServicesKit'; 3319 3320 appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data: boolean) => { 3321 console.log('checkAppAccountSyncEnable, result: ' + data); 3322 }).catch((err: BusinessError) => { 3323 console.log('checkAppAccountSyncEnable err: ' + JSON.stringify(err)); 3324 }); 3325 ``` 3326 3327### setAccountCredential<sup>(deprecated)</sup> 3328 3329setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void 3330 3331Set credentials for an app account. This API uses an asynchronous callback to return the result. 3332 3333> **NOTE** 3334> 3335> This API is supported since API version 7 and deprecated since API version 9. Use [setCredential](#setcredential9) instead. 3336 3337**System capability**: SystemCapability.Account.AppAccount 3338 3339**Parameters** 3340 3341| Name | Type | Mandatory | Description | 3342| -------------- | ------------------------- | ---- | ------------- | 3343| name | string | Yes | Name of the target app account. | 3344| credentialType | string | Yes | Type of the credential to set. | 3345| credential | string | Yes | Credential value. | 3346| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3347 3348**Example** 3349 3350 ```ts 3351 import { BusinessError } from '@kit.BasicServicesKit'; 3352 3353 appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err: BusinessError) => { 3354 console.log('setAccountCredential err: ' + JSON.stringify(err)); 3355 }); 3356 ``` 3357 3358### setAccountCredential<sup>(deprecated)</sup> 3359 3360setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> 3361 3362Set credentials for an app account. This API uses a promise to return the result. 3363 3364> **NOTE** 3365> 3366> This API is supported since API version 7 and deprecated since API version 9. Use [setCredential](#setcredential9-1) instead. 3367 3368**System capability**: SystemCapability.Account.AppAccount 3369 3370**Parameters** 3371 3372| Name | Type | Mandatory | Description | 3373| -------------- | ------ | ---- | ---------- | 3374| name | string | Yes | Name of the target app account. | 3375| credentialType | string | Yes | Type of the credential to set. | 3376| credential | string | Yes | Credential value. | 3377 3378**Return value** 3379 3380| Type | Description | 3381| :------------------ | :-------------------- | 3382| Promise<void> | Promise that returns no value. | 3383 3384**Example** 3385 3386 ```ts 3387 import { BusinessError } from '@kit.BasicServicesKit'; 3388 3389 appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => { 3390 console.log('setAccountCredential Success'); 3391 }).catch((err: BusinessError) => { 3392 console.log('setAccountCredential err: ' + JSON.stringify(err)); 3393 }); 3394 ``` 3395 3396### setAccountExtraInfo<sup>(deprecated)</sup> 3397 3398setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void 3399 3400Sets additional information for an app account. This API uses an asynchronous callback to return the result. 3401 3402> **NOTE** 3403> 3404> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9) instead. 3405 3406 3407**System capability**: SystemCapability.Account.AppAccount 3408 3409**Parameters** 3410 3411| Name | Type | Mandatory | Description | 3412| --------- | ------------------------- | ---- | --------------- | 3413| name | string | Yes | Name of the target app account. | 3414| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token. | 3415| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3416 3417**Example** 3418 3419 ```ts 3420 import { BusinessError } from '@kit.BasicServicesKit'; 3421 3422 appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err: BusinessError) => { 3423 console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); 3424 }); 3425 ``` 3426 3427### setAccountExtraInfo<sup>(deprecated)</sup> 3428 3429setAccountExtraInfo(name: string, extraInfo: string): Promise<void> 3430 3431Sets additional information for an app account. This API uses a promise to return the result. 3432 3433> **NOTE** 3434> 3435> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9-1) instead. 3436 3437 3438**System capability**: SystemCapability.Account.AppAccount 3439 3440**Parameters** 3441 3442| Name | Type | Mandatory | Description | 3443| --------- | ------ | ---- | --------- | 3444| name | string | Yes | Name of the target app account. | 3445| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token. | 3446 3447**Return value** 3448 3449| Type | Description | 3450| :------------------ | :-------------------- | 3451| Promise<void> | Promise that returns no value. | 3452 3453**Example** 3454 3455 ```ts 3456 import { BusinessError } from '@kit.BasicServicesKit'; 3457 3458 appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => { 3459 console.log('setAccountExtraInfo Success'); 3460 }).catch((err: BusinessError) => { 3461 console.log('setAccountExtraInfo err: ' + JSON.stringify(err)); 3462 }); 3463 ``` 3464 3465### setAppAccountSyncEnable<sup>(deprecated)</sup> 3466 3467setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void 3468 3469Sets data synchronization for an app account. This API uses an asynchronous callback to return the result. 3470 3471> **NOTE** 3472> 3473> This API is supported since API version 7 and deprecated since API version 9. Use [setDataSyncEnabled](#setdatasyncenabled9) instead. 3474 3475**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3476 3477**System capability**: SystemCapability.Account.AppAccount 3478 3479**Parameters** 3480 3481| Name | Type | Mandatory | Description | 3482| -------- | ------------------------- | ---- | ------------------------- | 3483| name | string | Yes | Name of the target app account. | 3484| isEnable | boolean | Yes | Whether to enable data synchronization. | 3485| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3486 3487**Example** 3488 3489 ```ts 3490 import { BusinessError } from '@kit.BasicServicesKit'; 3491 3492 appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err: BusinessError) => { 3493 console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); 3494 }); 3495 ``` 3496 3497### setAppAccountSyncEnable<sup>(deprecated)</sup> 3498 3499setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> 3500 3501Sets data synchronization for an app account. This API uses a promise to return the result. 3502 3503> **NOTE** 3504> 3505> This API is supported since API version 7 and deprecated since API version 9. Use [setDataSyncEnabled](#setdatasyncenabled9-1) instead. 3506 3507**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3508 3509**System capability**: SystemCapability.Account.AppAccount 3510 3511**Parameters** 3512 3513| Name | Type | Mandatory | Description | 3514| -------- | ------- | ---- | ----------- | 3515| name | string | Yes | Name of the target app account. | 3516| isEnable | boolean | Yes | Whether to enable data synchronization. | 3517 3518**Return value** 3519 3520| Type | Description | 3521| :------------------ | :-------------------- | 3522| Promise<void> | Promise that returns no value. | 3523 3524**Example** 3525 3526 ```ts 3527 import { BusinessError } from '@kit.BasicServicesKit'; 3528 3529 appAccountManager .setAppAccountSyncEnable('ZhangSan', true).then(() => { 3530 console.log('setAppAccountSyncEnable Success'); 3531 }).catch((err: BusinessError) => { 3532 console.log('setAppAccountSyncEnable err: ' + JSON.stringify(err)); 3533 }); 3534 ``` 3535 3536### setAssociatedData<sup>(deprecated)</sup> 3537 3538setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void 3539 3540Sets data to be associated with an app account. This API uses an asynchronous callback to return the result. 3541 3542> **NOTE** 3543> 3544> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9) instead. 3545 3546 3547**System capability**: SystemCapability.Account.AppAccount 3548 3549**Parameters** 3550 3551| Name | Type | Mandatory | Description | 3552| -------- | ------------------------- | ---- | ----------------- | 3553| name | string | Yes | Name of the target app account. | 3554| key | string | Yes | Key of the data to set. | 3555| value | string | Yes | Value of the data to set. | 3556| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3557 3558**Example** 3559 3560 ```ts 3561 import { BusinessError } from '@kit.BasicServicesKit'; 3562 3563 appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err: BusinessError) => { 3564 console.log('setAssociatedData err: ' + JSON.stringify(err)); 3565 }); 3566 ``` 3567 3568### setAssociatedData<sup>(deprecated)</sup> 3569 3570setAssociatedData(name: string, key: string, value: string): Promise<void> 3571 3572Sets data to be associated with an app account. This API uses a promise to return the result. 3573 3574> **NOTE** 3575> 3576> This API is supported since API version 7 and deprecated since API version 9. Use [setCustomData](#setcustomdata9-1) instead. 3577 3578 3579**System capability**: SystemCapability.Account.AppAccount 3580 3581**Parameters** 3582 3583| Name | Type | Mandatory | Description | 3584| ----- | ------ | ---- | ----------------- | 3585| name | string | Yes | Name of the target app account. | 3586| key | string | Yes | Key of the data to set. | 3587| value | string | Yes | Value of the data to set. | 3588 3589**Return value** 3590 3591| Type | Description | 3592| :------------------ | :-------------------- | 3593| Promise<void> | Promise that returns no value. | 3594 3595**Example** 3596 3597 ```ts 3598 import { BusinessError } from '@kit.BasicServicesKit'; 3599 3600 appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => { 3601 console.log('setAssociatedData Success'); 3602 }).catch((err: BusinessError) => { 3603 console.log('setAssociatedData err: ' + JSON.stringify(err)); 3604 }); 3605 ``` 3606 3607### getAllAccessibleAccounts<sup>(deprecated)</sup> 3608 3609getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 3610 3611Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. 3612 3613> **NOTE** 3614> 3615> This API is supported since API version 7 and deprecated since API version 9. Use [getAllAccounts](#getallaccounts9) instead. 3616 3617**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3618 3619**System capability**: SystemCapability.Account.AppAccount 3620 3621**Parameters** 3622 3623| Name | Type | Mandatory | Description | 3624| -------- | ---------------------------------------- | ---- | --------- | 3625| 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 app accounts. Otherwise, **err** is an error object. | 3626 3627**Example** 3628 3629 ```ts 3630 import { BusinessError } from '@kit.BasicServicesKit'; 3631 3632 appAccountManager.getAllAccessibleAccounts((err: BusinessError, data: appAccount.AppAccountInfo[])=>{ 3633 console.debug('getAllAccessibleAccounts err: ' + JSON.stringify(err)); 3634 console.debug('getAllAccessibleAccounts data: ' + JSON.stringify(data)); 3635 }); 3636 ``` 3637 3638### getAllAccessibleAccounts<sup>(deprecated)</sup> 3639 3640getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> 3641 3642Obtains information about all accessible app accounts. This API uses a promise to return the result. 3643 3644> **NOTE** 3645> 3646> This API is supported since API version 7 and deprecated since API version 9. Use [getAllAccounts](#getallaccounts9-1) instead. 3647 3648**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3649 3650**System capability**: SystemCapability.Account.AppAccount 3651 3652**Return value** 3653 3654| Type | Description | 3655| ---------------------------------------- | --------------------- | 3656| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the accessible app accounts.| 3657 3658**Example** 3659 3660 ```ts 3661 import { BusinessError } from '@kit.BasicServicesKit'; 3662 3663 appAccountManager.getAllAccessibleAccounts().then((data: appAccount.AppAccountInfo[]) => { 3664 console.log('getAllAccessibleAccounts: ' + data); 3665 }).catch((err: BusinessError) => { 3666 console.log('getAllAccessibleAccounts err: ' + JSON.stringify(err)); 3667 }); 3668 ``` 3669 3670### getAllAccounts<sup>(deprecated)</sup> 3671 3672getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void 3673 3674Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result. 3675 3676> **NOTE** 3677> 3678> This API is supported since API version 7 and deprecated since API version 9. Use [getAccountsByOwner](#getaccountsbyowner9) instead. 3679 3680**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3681 3682**System capability**: SystemCapability.Account.AppAccount 3683 3684**Parameters** 3685 3686| Name | Type | Mandatory | Description | 3687| -------- | ---------------------------------------- | ---- | --------- | 3688| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3689| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback used to return information about all accessible app accounts. | 3690 3691**Example** 3692 3693 ```ts 3694 import { BusinessError } from '@kit.BasicServicesKit'; 3695 3696 const selfBundle = 'com.example.actsgetallaaccounts'; 3697 appAccountManager.getAllAccounts(selfBundle, (err: BusinessError, data: appAccount.AppAccountInfo[])=>{ 3698 console.debug('getAllAccounts err: ' + JSON.stringify(err)); 3699 console.debug('getAllAccounts data:' + JSON.stringify(data)); 3700 }); 3701 ``` 3702 3703### getAllAccounts<sup>(deprecated)</sup> 3704 3705getAllAccounts(owner: string): Promise<Array<AppAccountInfo>> 3706 3707Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. 3708 3709> **NOTE** 3710> 3711> This API is supported since API version 7 and deprecated since API version 9. Use [getAccountsByOwner](#getaccountsbyowner9-1) instead. 3712 3713**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications) 3714 3715**System capability**: SystemCapability.Account.AppAccount 3716 3717**Parameters** 3718 3719| Name | Type | Mandatory | Description | 3720| ----- | ------ | ---- | ------ | 3721| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3722 3723**Return value** 3724 3725| Type | Description | 3726| ---------------------------------------- | --------------------- | 3727| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the app accounts that can be accessed by the invoker. | 3728 3729**Example** 3730 3731 ```ts 3732 import { BusinessError } from '@kit.BasicServicesKit'; 3733 3734 const selfBundle = 'com.example.actsgetallaaccounts'; 3735 appAccountManager.getAllAccounts(selfBundle).then((data: appAccount.AppAccountInfo[]) => { 3736 console.log('getAllAccounts: ' + data); 3737 }).catch((err: BusinessError) => { 3738 console.log('getAllAccounts err: ' + JSON.stringify(err)); 3739 }); 3740 ``` 3741 3742### getAccountCredential<sup>(deprecated)</sup> 3743 3744getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 3745 3746Obtains the credential of an app account. This API uses an asynchronous callback to return the result. 3747 3748> **NOTE** 3749> 3750> This API is supported since API version 7 and deprecated since API version 9. Use [getCredential](#getcredential9) instead. 3751 3752**System capability**: SystemCapability.Account.AppAccount 3753 3754**Parameters** 3755 3756| Name | Type | Mandatory | Description | 3757| -------------- | --------------------------- | ---- | -------------- | 3758| name | string | Yes | Name of the target app account. | 3759| credentialType | string | Yes | Type of the credential to obtain. | 3760| 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. | 3761 3762**Example** 3763 3764 ```ts 3765 import { BusinessError } from '@kit.BasicServicesKit'; 3766 3767 appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err: BusinessError, result: string) => { 3768 console.log('getAccountCredential err: ' + JSON.stringify(err)); 3769 console.log('getAccountCredential result: ' + result); 3770 }); 3771 ``` 3772 3773### getAccountCredential<sup>(deprecated)</sup> 3774 3775getAccountCredential(name: string, credentialType: string): Promise<string> 3776 3777Obtains the credential of an app account. This API uses a promise to return the result. 3778 3779> **NOTE** 3780> 3781> This API is supported since API version 7 and deprecated since API version 9. Use [getCredential](#getcredential9-1) instead. 3782 3783**System capability**: SystemCapability.Account.AppAccount 3784 3785**Parameters** 3786 3787| Name | Type | Mandatory | Description | 3788| -------------- | ------ | ---- | ---------- | 3789| name | string | Yes | Name of the target app account. | 3790| credentialType | string | Yes | Type of the credential to obtain. | 3791 3792**Return value** 3793 3794| Type | Description | 3795| :-------------------- | :-------------------- | 3796| Promise<string> | Promise used to return the credential obtained. | 3797 3798**Example** 3799 3800 ```ts 3801 import { BusinessError } from '@kit.BasicServicesKit'; 3802 3803 appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data: string) => { 3804 console.log('getAccountCredential, result: ' + data); 3805 }).catch((err: BusinessError) => { 3806 console.log('getAccountCredential err: ' + JSON.stringify(err)); 3807 }); 3808 ``` 3809 3810### getAccountExtraInfo<sup>(deprecated)</sup> 3811 3812getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void 3813 3814Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses an asynchronous callback to return the result. 3815 3816> **NOTE** 3817> 3818> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9) instead. 3819 3820**System capability**: SystemCapability.Account.AppAccount 3821 3822**Parameters** 3823 3824| Name | Type | Mandatory | Description | 3825| -------- | --------------------------- | ---- | --------------- | 3826| name | string | Yes | Name of the target app account. | 3827| 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. | 3828 3829**Example** 3830 3831 ```ts 3832 import { BusinessError } from '@kit.BasicServicesKit'; 3833 3834 appAccountManager.getAccountExtraInfo('ZhangSan', (err: BusinessError, result: string) => { 3835 console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); 3836 console.log('getAccountExtraInfo result: ' + result); 3837 }); 3838 ``` 3839 3840### getAccountExtraInfo<sup>(deprecated)</sup> 3841 3842getAccountExtraInfo(name: string): Promise<string> 3843 3844Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses a promise to return the result. 3845 3846> **NOTE** 3847> 3848> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9-1) instead. 3849 3850**System capability**: SystemCapability.Account.AppAccount 3851 3852**Parameters** 3853 3854| Name | Type | Mandatory | Description | 3855| ---- | ------ | ---- | ------- | 3856| name | string | Yes | Name of the target app account. | 3857 3858**Return value** 3859 3860| Type | Description | 3861| :-------------------- | :-------------------- | 3862| Promise<string> | Promise used to return the additional information obtained. | 3863 3864**Example** 3865 3866 ```ts 3867 import { BusinessError } from '@kit.BasicServicesKit'; 3868 3869 appAccountManager.getAccountExtraInfo('ZhangSan').then((data: string) => { 3870 console.log('getAccountExtraInfo, result: ' + data); 3871 }).catch((err: BusinessError) => { 3872 console.log('getAccountExtraInfo err: ' + JSON.stringify(err)); 3873 }); 3874 ``` 3875 3876### getAssociatedData<sup>(deprecated)</sup> 3877 3878getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void 3879 3880Obtains data associated with an app account. This API uses an asynchronous callback to return the result. 3881 3882> **NOTE** 3883> 3884> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9) instead. 3885 3886**System capability**: SystemCapability.Account.AppAccount 3887 3888**Parameters** 3889 3890| Name | Type | Mandatory | Description | 3891| -------- | --------------------------- | ---- | ----------------- | 3892| name | string | Yes | Name of the target app account. | 3893| key | string | Yes | Key of the data to obtain. | 3894| 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. | 3895 3896**Example** 3897 3898 ```ts 3899 import { BusinessError } from '@kit.BasicServicesKit'; 3900 3901 appAccountManager.getAssociatedData('ZhangSan', 'k001', (err: BusinessError, result: string) => { 3902 console.log('getAssociatedData err: ' + JSON.stringify(err)); 3903 console.log('getAssociatedData result: ' + result); 3904 }); 3905 ``` 3906 3907### getAssociatedData<sup>(deprecated)</sup> 3908 3909getAssociatedData(name: string, key: string): Promise<string> 3910 3911Obtains data associated with an app account. This API uses a promise to return the result. 3912 3913> **NOTE** 3914> 3915> This API is supported since API version 7 and deprecated since API version 9. Use [getCustomData](#getcustomdata9-1) instead. 3916 3917**System capability**: SystemCapability.Account.AppAccount 3918 3919**Parameters** 3920 3921| Name | Type | Mandatory | Description | 3922| ---- | ------ | ---- | --------- | 3923| name | string | Yes | Name of the target app account. | 3924| key | string | Yes | Key of the data to obtain. | 3925 3926**Return value** 3927 3928| Type | Description | 3929| :-------------------- | :-------------------- | 3930| Promise<string> | Promise used to return the data obtained. | 3931 3932**Example** 3933 3934 ```ts 3935 import { BusinessError } from '@kit.BasicServicesKit'; 3936 3937 appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data: string) => { 3938 console.log('getAssociatedData: ' + data); 3939 }).catch((err: BusinessError) => { 3940 console.log('getAssociatedData err: ' + JSON.stringify(err)); 3941 }); 3942 ``` 3943 3944### on('change')<sup>(deprecated)</sup> 3945 3946on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 3947 3948Subscribes to account information changes of apps. 3949 3950> **NOTE** 3951> 3952> This API is supported since API version 7 and deprecated since API version 9. Use [on('accountChange')](#onaccountchange9) instead. 3953 3954**System capability**: SystemCapability.Account.AppAccount 3955 3956**Parameters** 3957 3958| Name | Type | Mandatory | Description | 3959| -------- | ---------------------------------------- | ---- | ------------------------------ | 3960| type | 'change' | Yes | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes. | 3961| owners | Array<string> | Yes | App bundle names of the account. | 3962| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback registered to return the list of changed app accounts. | 3963 3964**Example** 3965 3966 ```ts 3967 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 3968 console.debug('receive change data:' + JSON.stringify(data)); 3969 } 3970 try{ 3971 appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback); 3972 } 3973 catch(err){ 3974 console.error('on accountOnOffDemo err:' + JSON.stringify(err)); 3975 } 3976 ``` 3977 3978### off('change')<sup>(deprecated)</sup> 3979 3980off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void 3981 3982Unsubscribes from account information changes. 3983 3984> **NOTE** 3985> 3986> This API is supported since API version 7 and deprecated since API version 9. Use [off('accountChange')](#offaccountchange9) instead. 3987 3988**System capability**: SystemCapability.Account.AppAccount 3989 3990**Parameters** 3991 3992| Name | Type | Mandatory | Description | 3993| -------- | -------------------------------- | ---- | ------------ | 3994| type | 'change' | Yes | Event type to unsubscribe from. The value is **'change'**, which indicates the account change event. | 3995| 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. | 3996 3997**Example** 3998 3999 ```ts 4000 function changeOnCallback(data: appAccount.AppAccountInfo[]): void { 4001 console.debug('receive change data: ' + JSON.stringify(data)); 4002 appAccountManager.off('change', () => { 4003 console.debug('off finish'); 4004 }) 4005 } 4006 try{ 4007 appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback); 4008 } 4009 catch(err){ 4010 console.error('on accountOnOffDemo err: ' + JSON.stringify(err)); 4011 } 4012 ``` 4013 4014### authenticate<sup>(deprecated)</sup> 4015 4016authenticate(name: string, owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 4017 4018Authenticates an app account with customized options. This API uses an asynchronous callback to return the result. 4019 4020> **NOTE** 4021> 4022> This API is supported since API version 8 and deprecated since API version 9. Use [auth](#auth9) instead. 4023 4024**System capability**: SystemCapability.Account.AppAccount 4025 4026**Parameters** 4027 4028| Name | Type | Mandatory | Description | 4029| -------- | --------------------- | ---- | --------------- | 4030| name | string | Yes | Name of the target app account. | 4031| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4032| authType | string | Yes | Authentication type. | 4033| options | {[key: string]: any} | Yes | Options for the authentication. | 4034| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Callback used to return the result. | 4035 4036**Example** 4037 4038 ```ts 4039 import { BusinessError } from '@kit.BasicServicesKit'; 4040 import { Want, common } from '@kit.AbilityKit'; 4041 4042 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 4043 4044 function onResultCallback(code: number, result: Record<string, Object>): void { 4045 console.log('resultCode: ' + code); 4046 console.log('result: ' + JSON.stringify(result)); 4047 } 4048 4049 function onRequestRedirectedCallback(request: Want): void { 4050 let wantInfo: Want = { 4051 deviceId: '', 4052 bundleName: 'com.example.accountjsdemo', 4053 action: 'ohos.want.action.viewData', 4054 entities: ['entity.system.default'], 4055 } 4056 context.startAbility(wantInfo).then(() => { 4057 console.log('startAbility successfully'); 4058 }).catch((err: BusinessError) => { 4059 console.log('startAbility err: ' + JSON.stringify(err)); 4060 }) 4061 } 4062 4063 appAccountManager.authenticate('LiSi', 'com.example.accountjsdemo', 'getSocialData', {}, { 4064 onResult: onResultCallback, 4065 onRequestRedirected: onRequestRedirectedCallback 4066 }); 4067 ``` 4068 4069### getOAuthToken<sup>(deprecated)</sup> 4070 4071getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 4072 4073Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 4074 4075> **NOTE** 4076> 4077> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthToken](#getauthtoken9) instead. 4078 4079**System capability**: SystemCapability.Account.AppAccount 4080 4081**Parameters** 4082 4083| Name | Type | Mandatory | Description | 4084| -------- | --------------------------- | ---- | ----------- | 4085| name | string | Yes | Name of the target app account. | 4086| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4087| authType | string | Yes | Authentication type. | 4088| 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. | 4089 4090**Example** 4091 4092 ```ts 4093 import { BusinessError } from '@kit.BasicServicesKit'; 4094 4095 appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 4096 (err: BusinessError, data: string) => { 4097 console.log('getOAuthToken err: ' + JSON.stringify(err)); 4098 console.log('getOAuthToken token: ' + data); 4099 }); 4100 ``` 4101 4102### getOAuthToken<sup>(deprecated)</sup> 4103 4104getOAuthToken(name: string, owner: string, authType: string): Promise<string> 4105 4106Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 4107 4108> **NOTE** 4109> 4110> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthToken](#getauthtoken9-1) instead. 4111 4112**System capability**: SystemCapability.Account.AppAccount 4113 4114**Parameters** 4115 4116| Name | Type | Mandatory | Description | 4117| -------- | ------ | ---- | ----------- | 4118| name | string | Yes | Name of the target app account. | 4119| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4120| authType | string | Yes | Authentication type. | 4121 4122**Return value** 4123 4124| Type | Description | 4125| --------------------- | --------------------- | 4126| Promise<string> | Promise used to return the result. | 4127 4128**Example** 4129 4130 ```ts 4131 import { BusinessError } from '@kit.BasicServicesKit'; 4132 4133 appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data: string) => { 4134 console.log('getOAuthToken token: ' + data); 4135 }).catch((err: BusinessError) => { 4136 console.log('getOAuthToken err: ' + JSON.stringify(err)); 4137 }); 4138 ``` 4139 4140### setOAuthToken<sup>(deprecated)</sup> 4141 4142setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 4143 4144Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. 4145 4146> **NOTE** 4147> 4148> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthToken](#setauthtoken9) instead. 4149 4150**System capability**: SystemCapability.Account.AppAccount 4151 4152**Parameters** 4153 4154| Name | Type | Mandatory | Description | 4155| -------- | ------------------------- | ---- | -------- | 4156| name | string | Yes | Name of the target app account. | 4157| authType | string | Yes | Authentication type. | 4158| token | string | Yes | Authorization token to set. | 4159| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4160 4161**Example** 4162 4163 ```ts 4164 import { BusinessError } from '@kit.BasicServicesKit'; 4165 4166 appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => { 4167 console.log('setOAuthToken err: ' + JSON.stringify(err)); 4168 }); 4169 ``` 4170 4171### setOAuthToken<sup>(deprecated)</sup> 4172 4173setOAuthToken(name: string, authType: string, token: string): Promise<void> 4174 4175Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. 4176 4177> **NOTE** 4178> 4179> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthToken](#setauthtoken9-1) instead. 4180 4181**System capability**: SystemCapability.Account.AppAccount 4182 4183**Parameters** 4184 4185| Name | Type | Mandatory | Description | 4186| -------- | ------ | ---- | -------- | 4187| name | string | Yes | Name of the target app account. | 4188| authType | string | Yes | Authentication type. | 4189| token | string | Yes | Authorization token to set. | 4190 4191**Return value** 4192 4193| Type | Description | 4194| ------------------- | --------------------- | 4195| Promise<void> | Promise that returns no value. | 4196 4197**Example** 4198 4199 ```ts 4200 import { BusinessError } from '@kit.BasicServicesKit'; 4201 4202 appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => { 4203 console.log('setOAuthToken successfully'); 4204 }).catch((err: BusinessError) => { 4205 console.log('setOAuthToken err: ' + JSON.stringify(err)); 4206 }); 4207 ``` 4208 4209### deleteOAuthToken<sup>(deprecated)</sup> 4210 4211deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 4212 4213Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 4214 4215> **NOTE** 4216> 4217> This API is supported since API version 8 and deprecated since API version 9. Use [deleteAuthToken](#deleteauthtoken9) instead. 4218 4219**System capability**: SystemCapability.Account.AppAccount 4220 4221**Parameters** 4222 4223| Name | Type | Mandatory | Description | 4224| -------- | ------------------------- | ---- | ------------ | 4225| name | string | Yes | Name of the target app account. | 4226| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4227| authType | string | Yes | Authentication type. | 4228| token | string | Yes | Authorization token to delete.| 4229| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4230 4231**Example** 4232 4233 ```ts 4234 import { BusinessError } from '@kit.BasicServicesKit'; 4235 4236 appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx', 4237 (err: BusinessError) => { 4238 console.log('deleteOAuthToken err: ' + JSON.stringify(err)); 4239 }); 4240 ``` 4241 4242### deleteOAuthToken<sup>(deprecated)</sup> 4243 4244deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 4245 4246Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 4247 4248> **NOTE** 4249> 4250> This API is supported since API version 8 and deprecated since API version 9. Use [deleteAuthToken](#deleteauthtoken9-1) instead. 4251 4252**System capability**: SystemCapability.Account.AppAccount 4253 4254**Parameters** 4255 4256| Name | Type | Mandatory | Description | 4257| -------- | ------ | ---- | ------------ | 4258| name | string | Yes | Name of the target app account. | 4259| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4260| authType | string | Yes | Authentication type. | 4261| token | string | Yes | Authorization token to delete.| 4262 4263**Return value** 4264 4265| Type | Description | 4266| ------------------- | --------------------- | 4267| Promise<void> | Promise that returns no value. | 4268 4269**Example** 4270 4271 ```ts 4272 import { BusinessError } from '@kit.BasicServicesKit'; 4273 4274 appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => { 4275 console.log('deleteOAuthToken successfully'); 4276 }).catch((err: BusinessError) => { 4277 console.log('deleteOAuthToken err: ' + JSON.stringify(err)); 4278 }); 4279 ``` 4280 4281### setOAuthTokenVisibility<sup>(deprecated)</sup> 4282 4283setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 4284 4285Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. 4286 4287> **NOTE** 4288> 4289> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthTokenVisibility](#setauthtokenvisibility9) instead. 4290 4291**System capability**: SystemCapability.Account.AppAccount 4292 4293**Parameters** 4294 4295| Name | Type | Mandatory | Description | 4296| ---------- | ------------------------- | ---- | ------------------------- | 4297| name | string | Yes | Name of the target app account. | 4298| authType | string | Yes | Authentication type. | 4299| bundleName | string | Yes | Bundle name of the app. | 4300| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 4301| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4302 4303**Example** 4304 4305 ```ts 4306 import { BusinessError } from '@kit.BasicServicesKit'; 4307 4308 appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true, 4309 (err: BusinessError) => { 4310 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4311 }); 4312 ``` 4313 4314### setOAuthTokenVisibility<sup>(deprecated)</sup> 4315 4316setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 4317 4318Sets the visibility of an authorization token to an app. This API uses a promise to return the result. 4319 4320> **NOTE** 4321> 4322> This API is supported since API version 8 and deprecated since API version 9. Use [setAuthTokenVisibility](#setauthtokenvisibility9-1) instead. 4323 4324**System capability**: SystemCapability.Account.AppAccount 4325 4326**Parameters** 4327 4328| Name | Type | Mandatory | Description | 4329| ---------- | ------- | ---- | ------------ | 4330| name | string | Yes | Name of the target app account. | 4331| authType | string | Yes | Authentication type. | 4332| bundleName | string | Yes | Bundle name of the app. | 4333| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 4334 4335**Return value** 4336 4337| Type | Description | 4338| ------------------- | --------------------- | 4339| Promise<void> | Promise that returns no value. | 4340 4341**Example** 4342 4343 ```ts 4344 import { BusinessError } from '@kit.BasicServicesKit'; 4345 4346 appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => { 4347 console.log('setOAuthTokenVisibility successfully'); 4348 }).catch((err: BusinessError) => { 4349 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4350 }); 4351 ``` 4352 4353### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4354 4355checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 4356 4357Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. 4358 4359> **NOTE** 4360> 4361> This API is supported since API version 8 and deprecated since API version 9. Use [checkAuthTokenVisibility](#checkauthtokenvisibility9) instead. 4362 4363**System capability**: SystemCapability.Account.AppAccount 4364 4365**Parameters** 4366 4367| Name | Type | Mandatory | Description | 4368| ---------- | ---------------------------- | ---- | ----------- | 4369| name | string | Yes | Name of the target app account. | 4370| authType | string | Yes | Authentication type. | 4371| bundleName | string | Yes | Bundle name of the app. | 4372| 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 app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | 4373 4374**Example** 4375 4376 ```ts 4377 import { BusinessError } from '@kit.BasicServicesKit'; 4378 4379 appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', 4380 (err: BusinessError, data: boolean) => { 4381 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4382 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4383 }); 4384 ``` 4385 4386### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4387 4388checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 4389 4390Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. 4391 4392> **NOTE** 4393> 4394> This API is supported since API version 8 and deprecated since API version 9. Use [checkAuthTokenVisibility](#checkauthtokenvisibility9-1) instead. 4395 4396**System capability**: SystemCapability.Account.AppAccount 4397 4398**Parameters** 4399 4400| Name | Type | Mandatory | Description | 4401| ---------- | ------ | ---- | ------------- | 4402| name | string | Yes | Name of the target app account. | 4403| authType | string | Yes | Authentication type. | 4404| bundleName | string | Yes | Bundle name of the app. | 4405 4406**Return value** 4407 4408| Type | Description | 4409| ---------------------- | --------------------- | 4410| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 4411 4412**Example** 4413 4414 ```ts 4415 import { BusinessError } from '@kit.BasicServicesKit'; 4416 4417 appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then(( 4418 data: boolean) => { 4419 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4420 }).catch((err: BusinessError) => { 4421 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4422 }); 4423 ``` 4424 4425### getAllOAuthTokens<sup>(deprecated)</sup> 4426 4427getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void 4428 4429Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. 4430 4431> **NOTE** 4432> 4433> This API is supported since API version 8 and deprecated since API version 9. Use [getAllAuthTokens](#getallauthtokens9) instead. 4434 4435**System capability**: SystemCapability.Account.AppAccount 4436 4437**Parameters** 4438 4439| Name | Type | Mandatory | Description | 4440| -------- | ---------------------------------------- | ---- | ----------- | 4441| name | string | Yes | Name of the target app account. | 4442| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4443| 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. | 4444 4445**Example** 4446 4447 ```ts 4448 import { BusinessError } from '@kit.BasicServicesKit'; 4449 4450 appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo', 4451 (err: BusinessError, data: appAccount.OAuthTokenInfo[]) => { 4452 console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); 4453 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4454 }); 4455 ``` 4456 4457### getAllOAuthTokens<sup>(deprecated)</sup> 4458 4459getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> 4460 4461Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. 4462 4463> **NOTE** 4464> 4465> This API is supported since API version 8 and deprecated since API version 9. Use [getAllAuthTokens](#getallauthtokens9-1) instead. 4466 4467**System capability**: SystemCapability.Account.AppAccount 4468 4469**Parameters** 4470 4471| Name | Type | Mandatory | Description | 4472| ----- | ------ | ---- | ----------- | 4473| name | string | Yes | Name of the target app account. | 4474| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4475 4476**Return value** 4477 4478| Type | Description | 4479| ---------------------------------------- | --------------------- | 4480| Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Promise used to return the tokens obtained. | 4481 4482**Example** 4483 4484 ```ts 4485 import { BusinessError } from '@kit.BasicServicesKit'; 4486 4487 appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then(( 4488 data: appAccount.OAuthTokenInfo[]) => { 4489 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4490 }).catch((err: BusinessError) => { 4491 console.log('getAllOAuthTokens err: ' + JSON.stringify(err)); 4492 }); 4493 ``` 4494 4495### getOAuthList<sup>(deprecated)</sup> 4496 4497getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 4498 4499Obtains the authorization list of the specified authentication type for an app 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. 4500 4501> **NOTE** 4502> 4503> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthList](#getauthlist9) instead. 4504 4505**System capability**: SystemCapability.Account.AppAccount 4506 4507**Parameters** 4508 4509| Name | Type | Mandatory | Description | 4510| -------- | ---------------------------------------- | ---- | ----------------------- | 4511| name | string | Yes | Name of the target app account. | 4512| authType | string | Yes | Authentication type. | 4513| 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. | 4514 4515**Example** 4516 4517 ```ts 4518 import { BusinessError } from '@kit.BasicServicesKit'; 4519 4520 appAccountManager.getOAuthList('LiSi', 'getSocialData', (err: BusinessError, data: string[]) => { 4521 console.log('getOAuthList err: ' + JSON.stringify(err)); 4522 console.log('getOAuthList data: ' + JSON.stringify(data)); 4523 }); 4524 ``` 4525 4526### getOAuthList<sup>(deprecated)</sup> 4527 4528getOAuthList(name: string, authType: string): Promise<Array<string>> 4529 4530Obtains the authorization list of the specified authentication type for an app 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. 4531 4532> **NOTE** 4533> 4534> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthList](#getauthlist9-1) instead. 4535 4536**System capability**: SystemCapability.Account.AppAccount 4537 4538**Parameters** 4539 4540| Name | Type | Mandatory | Description | 4541| -------- | ------ | ---- | ----------------------- | 4542| name | string | Yes | Name of the target app account. | 4543| authType | string | Yes | Authentication type. | 4544 4545**Return value** 4546 4547| Type | Description | 4548| ---------------------------------- | --------------------- | 4549| Promise<Array<string>> | Promise used to return a list of authorized bundles. | 4550 4551**Example** 4552 4553 ```ts 4554 import { BusinessError } from '@kit.BasicServicesKit'; 4555 4556 appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data: string[]) => { 4557 console.log('getOAuthList data: ' + JSON.stringify(data)); 4558 }).catch((err: BusinessError) => { 4559 console.log('getOAuthList err: ' + JSON.stringify(err)); 4560 }); 4561 ``` 4562 4563### getAuthenticatorCallback<sup>(deprecated)</sup> 4564 4565getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void 4566 4567Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. 4568 4569> **NOTE** 4570> 4571> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthCallback](#getauthcallback9) instead. 4572 4573**System capability**: SystemCapability.Account.AppAccount 4574 4575**Parameters** 4576 4577| Name | Type | Mandatory | Description | 4578| --------- | ---------------------------------------- | ---- | -------- | 4579| sessionId | string | Yes | ID of the authentication session. | 4580| 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. | 4581 4582**Example** 4583 4584 ```ts 4585 import { BusinessError } from '@kit.BasicServicesKit'; 4586 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 4587 4588 export default class EntryAbility extends UIAbility { 4589 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 4590 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 4591 appAccountManager.getAuthenticatorCallback(sessionId, 4592 (err: BusinessError, callback: appAccount.AuthenticatorCallback) => { 4593 if (err.code != appAccount.ResultCode.SUCCESS) { 4594 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 4595 return; 4596 } 4597 callback.onResult(appAccount.ResultCode.SUCCESS, { 4598 name: 'LiSi', 4599 owner: 'com.example.accountjsdemo', 4600 authType: 'getSocialData', 4601 token: 'xxxxxx'} 4602 ); 4603 }); 4604 } 4605 } 4606 ``` 4607 4608### getAuthenticatorCallback<sup>(deprecated)</sup> 4609 4610getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> 4611 4612Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. 4613 4614> **NOTE** 4615> 4616> This API is supported since API version 8 and deprecated since API version 9. Use [getAuthCallback](#getauthcallback9-1) instead. 4617 4618**System capability**: SystemCapability.Account.AppAccount 4619 4620**Parameters** 4621 4622| Name | Type | Mandatory | Description | 4623| --------- | ------ | ---- | -------- | 4624| sessionId | string | Yes | ID of the authentication session. | 4625 4626**Return value** 4627 4628| Type | Description | 4629| ------------------------------------ | --------------------- | 4630| Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Promise used to return the authenticator callback obtained. | 4631 4632**Example** 4633 4634 ```ts 4635 import { BusinessError } from '@kit.BasicServicesKit'; 4636 import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit'; 4637 4638 export default class EntryAbility extends UIAbility { 4639 onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function. 4640 let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string; 4641 appAccountManager.getAuthenticatorCallback(sessionId).then(( 4642 callback: appAccount.AuthenticatorCallback) => { 4643 callback.onResult(appAccount.ResultCode.SUCCESS, { 4644 name: 'LiSi', 4645 owner: 'com.example.accountjsdemo', 4646 authType: 'getSocialData', 4647 token: 'xxxxxx'} 4648 ); 4649 }).catch((err: BusinessError) => { 4650 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 4651 }); 4652 } 4653 } 4654 ``` 4655 4656### getAuthenticatorInfo<sup>(deprecated)</sup> 4657 4658getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 4659 4660Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. 4661 4662> **NOTE** 4663> 4664> This API is supported since API version 8 and deprecated since API version 9. Use [queryAuthenticatorInfo](#queryauthenticatorinfo9) instead. 4665 4666**System capability**: SystemCapability.Account.AppAccount 4667 4668**Parameters** 4669 4670| Name | Type | Mandatory | Description | 4671| -------- | -------------------------------------- | ---- | ----------- | 4672| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4673| 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. | 4674 4675**Example** 4676 4677 ```ts 4678 import { BusinessError } from '@kit.BasicServicesKit'; 4679 4680 appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo', 4681 (err: BusinessError, data: appAccount.AuthenticatorInfo) => { 4682 console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); 4683 console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); 4684 }); 4685 ``` 4686 4687### getAuthenticatorInfo<sup>(deprecated)</sup> 4688 4689getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 4690 4691Obtains the authenticator information of an app. This API uses a promise to return the result. 4692 4693> **NOTE** 4694> 4695> This API is supported since API version 8 and deprecated since API version 9. Use [queryAuthenticatorInfo](#queryauthenticatorinfo9-1) instead. 4696 4697**System capability**: SystemCapability.Account.AppAccount 4698 4699**Parameters** 4700 4701| Name | Type | Mandatory | Description | 4702| ----- | ------ | ---- | ----------- | 4703| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4704 4705**Return value** 4706 4707| Type | Description | 4708| -------------------------------- | --------------------- | 4709| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained. | 4710 4711**Example** 4712 4713 ```ts 4714 import { BusinessError } from '@kit.BasicServicesKit'; 4715 4716 appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then(( 4717 data: appAccount.AuthenticatorInfo) => { 4718 console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); 4719 }).catch((err: BusinessError) => { 4720 console.log('getAuthenticatorInfo err: ' + JSON.stringify(err)); 4721 }); 4722 ``` 4723 4724## AppAccountInfo 4725 4726Defines app account information. 4727 4728**System capability**: SystemCapability.Account.AppAccount 4729 4730| Name | Type | Mandatory | Description | 4731| ----- | ------ | ---- | ----------- | 4732| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 4733| name | string | Yes | Name of the target app account. | 4734 4735## AuthTokenInfo<sup>9+</sup> 4736 4737Defines authorization token information. 4738 4739**System capability**: SystemCapability.Account.AppAccount 4740 4741| Name | Type | Mandatory | Description | 4742| -------------------- | -------------- | ----- | ---------------- | 4743| authType<sup>9+</sup> | string | Yes | Authentication type. | 4744| token<sup>9+</sup> | string | Yes | Value of the authorization token. | 4745| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No | Information about the account to which the token belongs. By default, no value is passed in.| 4746 4747## OAuthTokenInfo<sup>(deprecated)</sup> 4748 4749Defines authorization token information. 4750 4751> **NOTE** 4752> 4753> This API is supported since API version 8 and deprecated since API version 9. Use [AuthTokenInfo](#authtokeninfo9) instead. 4754 4755**System capability**: SystemCapability.Account.AppAccount 4756 4757| Name | Type | Mandatory | Description | 4758| -------------------- | -------------- | ----- | ---------------- | 4759| authType | string | Yes | Authentication type. | 4760| token | string | Yes | Value of the authorization token. | 4761| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No | Information about the account to which the token belongs. By default, no value is passed in.| 4762 4763## AuthenticatorInfo<sup>8+</sup> 4764 4765Defines OAuth authenticator information. 4766 4767**System capability**: SystemCapability.Account.AppAccount 4768 4769| Name | Type | Mandatory | Description | 4770| ------- | ------ | ---- | ---------- | 4771| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the app. | 4772| iconId | number | Yes | ID of the authenticator icon. | 4773| labelId | number | Yes | ID of the authenticator label. | 4774 4775## AuthResult<sup>9+</sup> 4776 4777Defines the authentication result. 4778 4779**System capability**: SystemCapability.Account.AppAccount 4780 4781| Name | Type | Mandatory | Description | 4782| ------- | ------ | ---- | ---------- | 4783| account | [AppAccountInfo](#appaccountinfo) | No | Information about the account to which the token belongs. By default, no value is passed in. | 4784| tokenInfo | [AuthTokenInfo](#authtokeninfo9) | No | Token information. By default, no value is passed in. | 4785 4786## CreateAccountOptions<sup>9+</sup> 4787 4788Defines the options for creating an app account. 4789 4790**System capability**: SystemCapability.Account.AppAccount 4791 4792| Name | Type | Mandatory | Description | 4793| ------- | ------ | ---- | ---------- | 4794| customData | Record<string, string> | No | Custom data. By default, no value is passed in. | 4795 4796## CreateAccountImplicitlyOptions<sup>9+</sup> 4797 4798Defines the options for implicitly creating an app account. 4799 4800**System capability**: SystemCapability.Account.AppAccount 4801 4802| Name | Type | Mandatory | Description | 4803| ------- | ------ | ---- | ---------- | 4804| requiredLabels | Array<string> | No | Required labels. By default, no value is passed in. | 4805| authType | string | No | Authentication type. By default, no value is passed in. | 4806| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in. | 4807## SelectAccountsOptions<sup>9+</sup> 4808 4809Defines the options for selecting accounts. 4810 4811**System capability**: SystemCapability.Account.AppAccount 4812 4813| Name | Type | Mandatory | Description | 4814| --------------- | --------------------------- | ----- | ------------------- | 4815| allowedAccounts | Array<[AppAccountInfo](#appaccountinfo)> | No | Array of allowed accounts. By default, no value is passed in. | 4816| allowedOwners | Array<string> | No | Array of the owners of the allowed accounts. By default, no value is passed in. | 4817| requiredLabels | Array<string> | No | Labels of the authenticator. By default, no value is passed in. | 4818 4819## VerifyCredentialOptions<sup>9+</sup> 4820 4821Represents the options for verifying the user credential. 4822 4823**System capability**: SystemCapability.Account.AppAccount 4824 4825| Name | Type | Mandatory | Description | 4826| -------------- | ---------------------- | ----- | -------------- | 4827| credentialType | string | No | Credential type. By default, no value is passed in. | 4828| credential | string | No | Credential value. By default, no value is passed in. | 4829| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in. | 4830 4831 4832## SetPropertiesOptions<sup>9+</sup> 4833 4834Represents the options for setting authenticator properties. 4835 4836**System capability**: SystemCapability.Account.AppAccount 4837 4838| Name | Type | Mandatory | Description | 4839| ---------- | ---------------------- | ----- | -------------- | 4840| properties | Record<string, Object> | No | Property object. By default, no value is passed in. | 4841| parameters | Record<string, Object> | No | Custom parameter object. By default, no value is passed in. | 4842 4843## Constants<sup>8+</sup> 4844 4845Enumerates the constants. 4846 4847**System capability**: SystemCapability.Account.AppAccount 4848 4849| Name | Value | Description | 4850| -------------------------------- | ---------------------- | ----------------------- | 4851| ACTION_ADD_ACCOUNT_IMPLICITLY<sup>(deprecated)</sup> | 'addAccountImplicitly' | Operation of adding an account implicitly. | 4852| ACTION_AUTHENTICATE<sup>(deprecated)</sup> | 'authenticate' | Authentication operation. | 4853| ACTION_CREATE_ACCOUNT_IMPLICITLY<sup>9+</sup> | 'createAccountImplicitly' | Operation of creating an account implicitly. | 4854| ACTION_AUTH<sup>9+</sup> | 'auth' | Authentication operation. | 4855| ACTION_VERIFY_CREDENTIAL<sup>9+</sup> | 'verifyCredential' | Operation of verifying credentials. | 4856| ACTION_SET_AUTHENTICATOR_PROPERTIES<sup>9+</sup> | 'setAuthenticatorProperties' | Operation of setting authenticator properties. | 4857| KEY_NAME | 'name' | Name of the target app account. | 4858| KEY_OWNER | 'owner' | Bundle name of the app account owner.| 4859| KEY_TOKEN | 'token' | Token. | 4860| KEY_ACTION | 'action' | Operation. | 4861| KEY_AUTH_TYPE | 'authType' | Authentication type. | 4862| KEY_SESSION_ID | 'sessionId' | Session ID. | 4863| KEY_CALLER_PID | 'callerPid' | PID of the caller. | 4864| KEY_CALLER_UID | 'callerUid' | UID of the caller. | 4865| KEY_CALLER_BUNDLE_NAME | 'callerBundleName' | Bundle name of the caller. | 4866| KEY_REQUIRED_LABELS<sup>9+</sup> | 'requiredLabels' | Required labels. | 4867| KEY_BOOLEAN_RESULT<sup>9+</sup> | 'booleanResult' | Return value of the Boolean type. | 4868 4869## ResultCode<sup>(deprecated)</sup> 4870 4871Enumerates the result codes. 4872 4873> **NOTE**<br> 4874> This enum is supported since API version 8 and deprecated since API version 9. For details, see [Account Management Error Codes](errorcode-account.md). 4875 4876**System capability**: SystemCapability.Account.AppAccount 4877 4878| Name | Value | Description | 4879| ----------------------------------- | ----- | ------------ | 4880| SUCCESS | 0 | The operation is successful. | 4881| ERROR_ACCOUNT_NOT_EXIST | 10001 | The app account does not exist. | 4882| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. | 4883| ERROR_INVALID_PASSWORD | 10003 | The password is invalid. | 4884| ERROR_INVALID_REQUEST | 10004 | The request is invalid. | 4885| ERROR_INVALID_RESPONSE | 10005 | The response is invalid. | 4886| ERROR_NETWORK_EXCEPTION | 10006 | The network is abnormal. | 4887| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist. | 4888| ERROR_OAUTH_CANCELED | 10008 | The authentication is canceled. | 4889| ERROR_OAUTH_LIST_TOO_LARGE | 10009 | The size of the OAuth list exceeds the limit. | 4890| ERROR_OAUTH_SERVICE_BUSY | 10010 | The OAuth service is busy. | 4891| ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | The OAuth service is abnormal. | 4892| ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | The session to be authenticated does not exist. | 4893| ERROR_OAUTH_TIMEOUT | 10013 | The authentication timed out. | 4894| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | The authorization token does not exist. | 4895| ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | The number of OAuth tokens reaches the limit. | 4896| ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | The authentication operation is not supported. | 4897| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | The authentication type is not supported. | 4898| ERROR_PERMISSION_DENIED | 10018 | The required permission is missing. | 4899 4900## AuthCallback<sup>9+</sup> 4901 4902Implements authenticator callbacks. 4903 4904### onResult<sup>9+</sup> 4905 4906onResult: (code: number, result?: AuthResult) => void 4907 4908Called to return the result of an authentication request. 4909 4910**System capability**: SystemCapability.Account.AppAccount 4911 4912**Parameters** 4913 4914| Name | Type | Mandatory | Description | 4915| ------ | -------------------- | ---- | ------ | 4916| code | number | Yes | Authentication result code. | 4917| result | [AuthResult](#authresult9) | No | Authentication result. By default, no value is passed, which means the authentication result is not received. | 4918 4919**Example** 4920 4921 ```ts 4922 import { BusinessError } from '@kit.BasicServicesKit'; 4923 4924 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 4925 let sessionId = '1234'; 4926 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 4927 let result: appAccount.AuthResult = { 4928 account: { 4929 name: 'Lisi', 4930 owner: 'com.example.accountjsdemo', 4931 }, 4932 tokenInfo: { 4933 token: 'xxxxxx', 4934 authType: 'getSocialData' 4935 } 4936 }; 4937 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4938 }).catch((err: BusinessError) => { 4939 console.log('getAuthCallback err: ' + JSON.stringify(err)); 4940 }); 4941 ``` 4942 4943### onRequestRedirected<sup>9+</sup> 4944 4945onRequestRedirected: (request: Want) => void 4946 4947Called to redirect a request. 4948 4949**System capability**: SystemCapability.Account.AppAccount 4950 4951**Parameters** 4952 4953| Name | Type | Mandatory | Description | 4954| ------- | ---- | ---- | ---------- | 4955| request | Want | Yes | Request to be redirected. | 4956 4957**Example** 4958 4959 ```ts 4960 import { Want } from '@kit.AbilityKit'; 4961 4962 class MyAuthenticator extends appAccount.Authenticator { 4963 createAccountImplicitly( 4964 options: appAccount.CreateAccountImplicitlyOptions, callback: appAccount.AuthCallback) { 4965 let want: Want = { 4966 bundleName: 'com.example.accountjsdemo', 4967 abilityName: 'com.example.accountjsdemo.LoginAbility', 4968 }; 4969 callback.onRequestRedirected(want); 4970 } 4971 4972 auth(name: string, authType: string, 4973 options: Record<string, Object>, callback: appAccount.AuthCallback) { 4974 let result: appAccount.AuthResult = { 4975 account: { 4976 name: 'Lisi', 4977 owner: 'com.example.accountjsdemo', 4978 }, 4979 tokenInfo: { 4980 token: 'xxxxxx', 4981 authType: 'getSocialData' 4982 } 4983 }; 4984 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4985 } 4986 } 4987 ``` 4988 4989### onRequestContinued<sup>9+</sup> 4990 4991onRequestContinued?: () => void 4992 4993Called to continue to process the request. 4994 4995**System capability**: SystemCapability.Account.AppAccount 4996 4997**Example** 4998 4999 ```ts 5000 import { BusinessError } from '@kit.BasicServicesKit'; 5001 5002 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 5003 let sessionId = '1234'; 5004 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 5005 if (callback.onRequestContinued != undefined) { 5006 callback.onRequestContinued(); 5007 } 5008 }).catch((err: BusinessError) => { 5009 console.log('getAuthCallback err: ' + JSON.stringify(err)); 5010 }); 5011 ``` 5012 5013## AuthenticatorCallback<sup>(deprecated)</sup> 5014 5015Provides OAuth authenticator callbacks. 5016 5017> **NOTE** 5018> 5019> This API is supported since API version 8 and deprecated since API version 9. Use [AuthCallback](#authcallback9) instead. 5020 5021### onResult<sup>8+</sup> 5022 5023onResult: (code: number, result: {[key: string]: any;}) => void 5024 5025Called to return the result of an authentication request. 5026 5027**System capability**: SystemCapability.Account.AppAccount 5028 5029**Parameters** 5030 5031| Name | Type | Mandatory | Description | 5032| ------ | -------------------- | ---- | ------ | 5033| code | number | Yes | Authentication result code. | 5034| result | {[key: string]: any} | Yes | Authentication result. | 5035 5036**Example** 5037 5038 ```ts 5039 import { BusinessError } from '@kit.BasicServicesKit'; 5040 5041 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 5042 let sessionId = '1234'; 5043 appAccountManager.getAuthenticatorCallback(sessionId).then((callback: appAccount.AuthenticatorCallback) => { 5044 callback.onResult(appAccount.ResultCode.SUCCESS, { 5045 name: 'LiSi', 5046 owner: 'com.example.accountjsdemo', 5047 authType: 'getSocialData', 5048 token: 'xxxxxx'} 5049 ); 5050 }).catch((err: BusinessError) => { 5051 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 5052 }); 5053 ``` 5054 5055### onRequestRedirected<sup>8+</sup> 5056 5057onRequestRedirected: (request: Want) => void 5058 5059Called to redirect a request. 5060 5061**System capability**: SystemCapability.Account.AppAccount 5062 5063**Parameters** 5064 5065| Name | Type | Mandatory | Description | 5066| ------- | ---- | ---- | ---------- | 5067| request | Want | Yes | Request to be redirected. | 5068 5069**Example** 5070 5071 ```ts 5072 import { Want } from '@kit.AbilityKit'; 5073 5074 class MyAuthenticator extends appAccount.Authenticator { 5075 addAccountImplicitly(authType: string, callerBundleName: string, 5076 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5077 let want: Want = { 5078 bundleName: 'com.example.accountjsdemo', 5079 abilityName: 'com.example.accountjsdemo.LoginAbility', 5080 }; 5081 callback.onRequestRedirected(want); 5082 } 5083 5084 authenticate(name: string, authType: string, callerBundleName: string, 5085 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5086 callback.onResult(appAccount.ResultCode.SUCCESS, { 5087 name: name, 5088 authType: authType, 5089 token: 'xxxxxx'} 5090 ); 5091 } 5092 } 5093 ``` 5094 5095## Authenticator<sup>8+</sup> 5096 5097Provides APIs to operate the authenticator. 5098 5099### createAccountImplicitly<sup>9+</sup> 5100 5101createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 5102 5103Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. 5104 5105**System capability**: SystemCapability.Account.AppAccount 5106 5107**Parameters** 5108 5109| Name | Type | Mandatory | Description | 5110| ---------------- | --------------------- | ---- | --------------- | 5111| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | 5112| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 5113 5114### addAccountImplicitly<sup>(deprecated)</sup> 5115 5116addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5117 5118Adds an app account implicitly based on the specified authentication type and options. This API uses an asynchronous callback to return the result. 5119 5120> **NOTE** 5121> 5122> This API is supported since API version 8 and deprecated since API version 9. Use [createAccountImplicitly](#createaccountimplicitly9-2) instead. 5123 5124**System capability**: SystemCapability.Account.AppAccount 5125 5126**Parameters** 5127 5128| Name | Type | Mandatory | Description | 5129| ---------------- | --------------------- | ---- | --------------- | 5130| authType | string | Yes | Authentication type. | 5131| callerBundleName | string | Yes | Bundle name of the authentication requester. | 5132| options | {[key: string]: any} | Yes | Options for the authentication. | 5133| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the authentication result. | 5134 5135### auth<sup>9+</sup> 5136 5137auth(name: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void 5138 5139Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. 5140 5141**System capability**: SystemCapability.Account.AppAccount 5142 5143**Parameters** 5144 5145| Name | Type | Mandatory | Description | 5146| ---------------- | --------------------- | ---- | --------------- | 5147| name | string | Yes | Name of the target app account. | 5148| authType | string | Yes | Authentication type. | 5149| options | Record<string, Object> | Yes | Options for the authentication. | 5150| callback | [AuthCallback](#authcallback9) | Yes | Callback used to return the result. | 5151 5152### authenticate<sup>(deprecated)</sup> 5153 5154authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5155 5156Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. 5157 5158> **NOTE** 5159> 5160> This API is supported since API version 8 and deprecated since API version 9. Use [auth](#auth9-2) instead. 5161 5162**System capability**: SystemCapability.Account.AppAccount 5163 5164**Parameters** 5165 5166| Name | Type | Mandatory | Description | 5167| ---------------- | --------------------- | ---- | --------------- | 5168| name | string | Yes | Name of the target app account. | 5169| authType | string | Yes | Authentication type. | 5170| callerBundleName | string | Yes | Bundle name of the authentication requester. | 5171| options | {[key: string]: any} | Yes | Options for the authentication. | 5172| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback used to return the authentication result. | 5173 5174### verifyCredential<sup>9+</sup> 5175 5176verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void 5177 5178Verifies the credential of an app account. This API uses an asynchronous callback to return the result. 5179 5180**System capability**: SystemCapability.Account.AppAccount 5181 5182**Parameters** 5183 5184| Name | Type | Mandatory | Description | 5185| ---------------- | --------------------- | ---- | --------------- | 5186| name | string | Yes | Name of the target app account. | 5187| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for credential verification. | 5188| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the verification result. | 5189 5190### setProperties<sup>9+</sup> 5191 5192setProperties(options: SetPropertiesOptions, callback: AuthCallback): void 5193 5194Sets the authenticator properties. This API uses an asynchronous callback to return the result. 5195 5196**System capability**: SystemCapability.Account.AppAccount 5197 5198**Parameters** 5199 5200| Name | Type | Mandatory | Description | 5201| ---------------- | --------------------- | ---- | --------------- | 5202| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 5203| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 5204 5205### checkAccountLabels<sup>9+</sup> 5206 5207checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void 5208 5209Checks the account labels. This API uses an asynchronous callback to return the result. 5210 5211**System capability**: SystemCapability.Account.AppAccount 5212 5213**Parameters** 5214 5215| Name | Type | Mandatory | Description | 5216| ---------------- | --------------------- | ---- | --------------- | 5217| name | string | Yes | Name of the target app account. | 5218| labels | Array<string> | Yes | Labels to check. | 5219| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the check result. | 5220 5221### checkAccountRemovable<sup>9+</sup> 5222 5223checkAccountRemovable(name: string, callback: AuthCallback): void 5224 5225Checks whether an app account can be deleted. This API uses an asynchronous callback to return the result. 5226 5227**System capability**: SystemCapability.Account.AppAccount 5228 5229**Parameters** 5230 5231| Name | Type | Mandatory | Description | 5232| ---------------- | --------------------- | ---- | --------------- | 5233| name | string | Yes | Name of the target app account. | 5234| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 5235 5236### getRemoteObject<sup>9+</sup> 5237 5238getRemoteObject(): rpc.RemoteObject; 5239 5240Obtains the remote object of an authenticator. This API cannot be overloaded. 5241 5242**System capability**: SystemCapability.Account.AppAccount 5243 5244**Example** 5245 5246 ```ts 5247 import { rpc } from '@kit.IPCKit'; 5248 import { Want } from '@kit.AbilityKit'; 5249 5250 class MyAuthenticator extends appAccount.Authenticator { 5251 verifyCredential(name: string, 5252 options: appAccount.VerifyCredentialOptions, callback: appAccount.AuthCallback) { 5253 let want: Want = { 5254 bundleName: 'com.example.accountjsdemo', 5255 abilityName: 'com.example.accountjsdemo.VerifyAbility', 5256 parameters: { 5257 name: name 5258 } 5259 }; 5260 callback.onRequestRedirected(want); 5261 } 5262 5263 setProperties(options: appAccount.SetPropertiesOptions, callback: appAccount.AuthCallback) { 5264 let want: Want = { 5265 bundleName: 'com.example.accountjsdemo', 5266 abilityName: 'com.example.accountjsdemo.SetPropertiesAbility', 5267 parameters: { 5268 options: options 5269 } 5270 }; 5271 callback.onRequestRedirected(want); 5272 } 5273 5274 checkAccountLabels(name: string, labels: string[], callback: appAccount.AuthCallback) { 5275 callback.onResult(0); 5276 } 5277 5278 checkAccountRemovable(name: string, callback: appAccount.AuthCallback) { 5279 callback.onResult(0); 5280 } 5281 } 5282 5283 export default { 5284 onConnect(want: Want): rpc.RemoteObject { // serviceAbility lifecycle function, which needs to be placed in serviceAbility. 5285 let authenticator = new MyAuthenticator(); 5286 return authenticator.getRemoteObject(); 5287 } 5288 } 5289 ``` 5290