1# @ohos.account.appAccount (应用账号管理) 2 3本模块提供应用账号信息的添加、删除、修改和查询基础能力,并支持应用间鉴权和分布式数据同步功能。 4 5> **说明:** 6> 7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9 10## 导入模块 11 12```ts 13import { appAccount } from '@kit.BasicServicesKit'; 14``` 15 16 17## appAccount.createAppAccountManager 18 19createAppAccountManager(): AppAccountManager 20 21创建应用账号管理器对象。 22 23**系统能力:** SystemCapability.Account.AppAccount 24 25**返回值:** 26 27| 类型 | 说明 | 28| ----------------- | ------------ | 29| AppAccountManager | 应用账号管理器对象。 | 30 31**示例:** 32 ```ts 33 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 34 ``` 35 36## AppAccountManager 37 38应用账号管理器类。 39 40### createAccount<sup>9+</sup> 41 42createAccount(name: string, callback: AsyncCallback<void>): void 43 44根据账号名创建应用账号。使用callback异步回调。 45 46**系统能力:** SystemCapability.Account.AppAccount 47 48**参数:** 49 50| 参数名 | 类型 | 必填 | 说明 | 51| -------- | ------------------------- | ----- | -------------------- | 52| name | string | 是 | 应用账号的名称。 | 53| callback | AsyncCallback<void> | 是 | 回调函数。当创建成功时,err为null,否则为错误对象。 | 54 55**错误码:** 56 57| 错误码ID | 错误信息 | 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**示例:** 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 83根据账号名和可选项创建应用账号。使用callback异步回调。 84 85**系统能力:** SystemCapability.Account.AppAccount 86 87**参数:** 88 89| 参数名 | 类型 | 必填 | 说明 | 90| --------- | ------------------------- | ---- | ---------------------------------------- | 91| name | string | 是 | 应用账号的名称。 | 92| options | [CreateAccountOptions](#createaccountoptions9) | 是 | 创建应用账号的选项,可提供自定义数据,但不建议包含敏感数据(如密码、Token等)。 | 93| callback | AsyncCallback<void> | 是 | 回调函数。当创建成功时,err为null,否则为错误对象。 | 94 95**错误码:** 96 97| 错误码ID | 错误信息 | 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**示例:** 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 132根据账号名和可选项创建应用账号。使用Promise异步回调。 133 134**系统能力:** SystemCapability.Account.AppAccount 135 136**参数:** 137 138| 参数名 | 类型 | 必填 | 说明 | 139| --------- | ------ | ---- | ---------------------------------------- | 140| name | string | 是 | 应用账号的名称。 | 141| options | [CreateAccountOptions](#createaccountoptions9) | 否 | 创建应用账号的选项,可提供自定义数据,但不建议包含敏感数据(如密码、Token等)。不填无影响,默认为空,表示创建的该账号无额外信息需要添加。 | 142 143**返回值:** 144 145| 类型 | 说明 | 146| ------------------- | --------------------- | 147| Promise<void> | 无返回结果的Promise对象。 | 148 149**错误码:** 150 151| 错误码ID | 错误信息| 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**示例:** 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 184根据指定的账号所有者隐式地创建应用账号。使用callback异步回调。 185 186**系统能力:** SystemCapability.Account.AppAccount 187 188**参数:** 189 190| 参数名 | 类型 | 必填 | 说明 | 191| -------- | --------------------- | ---- | ----------------------- | 192| owner | string | 是 | 应用账号所有者的包名。 | 193| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调对象,返回创建结果。 | 194 195**错误码:** 196 197| 错误码ID | 错误信息| 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**示例:** 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 248根据指定的账号所有者和可选项隐式地创建应用账号。使用callback异步回调。 249 250**系统能力:** SystemCapability.Account.AppAccount 251 252**参数:** 253 254| 参数名 | 类型 | 必填 | 说明 | 255| -------- | --------------------- | ---- | ----------------------- | 256| owner | string | 是 | 应用账号所有者的包名。 | 257| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | 是 | 隐式创建账号的选项。 | 258| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调对象,返回创建结果。 | 259 260**错误码:** 261 262| 错误码ID | 错误信息 | 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**示例:** 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 317删除应用账号。使用callback异步回调。 318 319**系统能力:** SystemCapability.Account.AppAccount 320 321**参数:** 322 323| 参数名 | 类型 | 必填 | 说明 | 324| -------- | ------------------------- | ---- | ---------------- | 325| name | string | 是 | 应用账号的名称。 | 326| callback | AsyncCallback<void> | 是 | 回调函数。当删除成功时,err为null,否则为错误对象。 | 327 328**错误码:** 329 330| 错误码ID | 错误信息 | 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**示例:** 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 359删除应用账号。使用Promise异步回调。 360 361**系统能力:** SystemCapability.Account.AppAccount 362 363**参数:** 364 365| 参数名 | 类型 | 必填 | 说明 | 366| ---- | ------ | ---- | ----------- | 367| name | string | 是 | 应用账号的名称。 | 368 369**返回值:** 370 371| 类型 | 说明 | 372| :------------------ | :-------------------- | 373| Promise<void> | 无返回结果的Promise对象。 | 374 375**错误码:** 376 377| 错误码ID | 错误信息 | 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**示例:** 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 404设置指定应用对特定账号的访问权限。使用callback异步回调。 405 406**系统能力:** SystemCapability.Account.AppAccount 407 408**参数:** 409 410| 参数名 | 类型 | 必填 | 说明 | 411| ------------ | ------------------------- | ---- | --------------------------------- | 412| name | string | 是 | 应用账号的名称。 | 413| bundleName | string | 是 | 第三方应用的包名。 | 414| isAccessible | boolean | 是 | 是否可访问。true表示允许访问,false表示禁止访问。 | 415| callback | AsyncCallback<void> | 是 | 回调函数,如果设置成功,err为null,否则为错误对象。 | 416 417**错误码:** 418 419| 错误码ID | 错误信息| 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**示例:** 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 449设置指定应用对特定账号的数据访问权限。使用Promise异步回调。 450 451**系统能力:** SystemCapability.Account.AppAccount 452 453**参数:** 454 455| 参数名 | 类型 | 必填 | 说明 | 456| ---------- | ------ | ---- | --------- | 457| name | string | 是 | 应用账号的名称。 | 458| bundleName | string | 是 | 第三方应用的包名。 | 459| isAccessible | boolean | 是 | 是否可访问。true表示允许访问,false表示禁止访问。 | 460 461**返回值:** 462 463| 类型 | 说明 | 464| :------------------ | :-------------------- | 465| Promise<void> | 无返回结果的Promise对象。 | 466 467**错误码:** 468 469| 错误码ID | 错误信息| 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**示例:** 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 497检查指定应用对特定账号的数据是否可访问。使用callback异步回调。 498 499**系统能力:** SystemCapability.Account.AppAccount 500 501**参数:** 502 503| 参数名 | 类型 | 必填 | 说明 | 504| ---------- | ------------------------- | ---- | --------------------------------- | 505| name | string | 是 | 应用账号的名称。 | 506| bundleName | string | 是 | 第三方应用的包名。 | 507| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定应用可访问特定账号的数据;返回false表示不可访问。 | 508 509**错误码:** 510 511| 错误码ID | 错误信息 | 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**示例:** 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 541检查指定应用对特定账号的数据是否可访问。使用Promise异步回调。 542 543**系统能力:** SystemCapability.Account.AppAccount 544 545**参数:** 546 547| 参数名 | 类型 | 必填 | 说明 | 548| ---------- | ------ | ---- | --------- | 549| name | string | 是 | 应用账号的名称。 | 550| bundleName | string | 是 | 第三方应用的包名。 | 551 552**返回值:** 553 554| 类型 | 说明 | 555| ------------------- | --------------------- | 556| Promise<boolean> | Promise对象。返回true表示指定应用可访问特定账号的数据;返回false表示不可访问。 | 557 558**错误码:** 559 560| 错误码ID | 错误信息| 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**示例:** 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 587开启或禁止指定应用账号的数据同步功能。使用callback异步回调。 588 589**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 590 591**系统能力:** SystemCapability.Account.AppAccount 592 593**参数:** 594 595| 参数名 | 类型 | 必填 | 说明 | 596| -------- | ------------------------- | ---- | ------------------------- | 597| name | string | 是 | 应用账号的名称。 | 598| isEnabled | boolean | 是 | 是否开启数据同步。 | 599| callback | AsyncCallback<void> | 是 | 回调函数。当开启或禁止成功时,err为null,否则为错误对象。 | 600 601**错误码:** 602 603| 错误码ID | 错误信息| 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**示例:** 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 629开启或禁止指定应用账号的数据同步功能。使用Promise异步回调。 630 631**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 632 633**系统能力:** SystemCapability.Account.AppAccount 634 635**参数:** 636 637| 参数名 | 类型 | 必填 | 说明 | 638| -------- | ------- | ---- | ----------- | 639| name | string | 是 | 应用账号的名称。 | 640| isEnabled | boolean | 是 | 是否开启数据同步。 | 641 642**返回值:** 643 644| 类型 | 说明 | 645| :------------------ | :-------------------- | 646| Promise<void> | 无返回结果的Promise对象。 | 647 648**错误码:** 649 650| 错误码ID | 错误信息 | 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**示例:** 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 678检查指定应用账号是否开启数据同步功能。使用callback异步回调。 679 680**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 681 682**系统能力:** SystemCapability.Account.AppAccount 683 684**参数:** 685 686| 参数名 | 类型 | 必填 | 说明 | 687| -------- | ---------------------------- | ---- | --------------------- | 688| name | string | 是 | 应用账号的名称。 | 689| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定应用账号已开启数据同步功能;返回false表示未开启。 | 690 691**错误码:** 692 693| 错误码ID | 错误信息 | 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**示例:** 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 723检查指定应用账号是否开启数据同步功能。使用Promise异步回调。 724 725**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 726 727**系统能力:** SystemCapability.Account.AppAccount 728 729**参数:** 730 731| 参数名 | 类型 | 必填 | 说明 | 732| ---- | ------ | ---- | ------- | 733| name | string | 是 | 应用账号的名称。 | 734 735**返回值:** 736 737| 类型 | 说明 | 738| :--------------------- | :-------------------- | 739| Promise<boolean> | Promise对象。返回true表示指定应用账号已开启数据同步功能;返回false表示未开启。 | 740 741**错误码:** 742 743| 错误码ID | 错误信息| 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**示例:** 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 771设置指定应用账号的凭据。使用callback异步回调。 772 773**系统能力:** SystemCapability.Account.AppAccount 774 775**参数:** 776 777| 参数名 | 类型 | 必填 | 说明 | 778| -------------- | ------------------------- | ---- | ------------- | 779| name | string | 是 | 应用账号的名称。 | 780| credentialType | string | 是 | 凭据类型。 | 781| credential | string | 是 | 凭据取值。 | 782| callback | AsyncCallback<void> | 是 | 回调函数。当凭据设置成功时,err为null,否则为错误对象。 | 783 784**错误码:** 785 786| 错误码ID | 错误信息| 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**示例:** 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 815设置指定应用账号的凭据。使用Promise异步回调。 816 817**系统能力:** SystemCapability.Account.AppAccount 818 819**参数:** 820 821| 参数名 | 类型 | 必填 | 说明 | 822| -------------- | ------ | ---- | ---------- | 823| name | string | 是 | 应用账号的名称。 | 824| credentialType | string | 是 | 凭据类型。 | 825| credential | string | 是 | 凭据取值。 | 826 827**返回值:** 828 829| 类型 | 说明 | 830| :------------------ | :-------------------- | 831| Promise<void> | 无返回结果的Promise对象。 | 832 833**错误码:** 834 835| 错误码ID | 错误信息| 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**示例:** 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 862获取指定应用账号的凭据。使用callback异步回调。 863 864**系统能力:** SystemCapability.Account.AppAccount 865 866**参数:** 867 868| 参数名 | 类型 | 必填 | 说明 | 869| -------------- | --------------------------- | ---- | -------------- | 870| name | string | 是 | 应用账号的名称。 | 871| credentialType | string | 是 | 凭据类型。 | 872| callback | AsyncCallback<string> | 是 | 回调函数。当获取凭据成功时,err为null,data为指定应用账号的凭据;否则为错误对象。 | 873 874**错误码:** 875 876| 错误码ID | 错误信息 | 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**示例:** 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 906获取指定应用账号的凭据。使用Promise异步回调。 907 908**系统能力:** SystemCapability.Account.AppAccount 909 910**参数:** 911 912| 参数名 | 类型 | 必填 | 说明 | 913| -------------- | ------ | ---- | ---------- | 914| name | string | 是 | 应用账号的名称。 | 915| credentialType | string | 是 | 凭据类型。 | 916 917**返回值:** 918 919| 类型 | 说明 | 920| :-------------------- | :-------------------- | 921| Promise<string> | Promise对象,返回指定应用账号的凭据。 | 922 923**错误码:** 924 925| 错误码ID | 错误信息 | 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**示例:** 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 953设置指定应用账号的自定义数据。使用callback异步回调。 954 955**系统能力:** SystemCapability.Account.AppAccount 956 957**参数:** 958 959| 参数名 | 类型 | 必填 | 说明 | 960| -------- | ------------------------- | ---- | ----------------- | 961| name | string | 是 | 应用账号的名称。 | 962| key | string | 是 | 自定义数据的键名。 | 963| value | string | 是 | 自定义数据的取值。 | 964| callback | AsyncCallback<void> | 是 | 回调函数。当设置自定义数据成功时,err为null,否则为错误对象。 | 965 966**错误码:** 967 968| 错误码ID | 错误信息| 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**示例:** 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 998设置指定应用账号的自定义数据。使用Promise异步回调。 999 1000**系统能力:** SystemCapability.Account.AppAccount 1001 1002**参数:** 1003 1004| 参数名 | 类型 | 必填 | 说明 | 1005| ----- | ------ | ---- | ----------------- | 1006| name | string | 是 | 应用账号的名称。 | 1007| key | string | 是 | 自定义数据的键名。 | 1008| value | string | 是 | 自定义数据的取值。 | 1009 1010**返回值:** 1011 1012| 类型 | 说明 | 1013| :------------------ | :-------------------- | 1014| Promise<void> | 无返回结果的Promise对象。 | 1015 1016**错误码:** 1017 1018| 错误码ID | 错误信息| 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**示例:** 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 1046根据指定键名获取特定应用账号的自定义数据。使用callback异步回调。 1047 1048**系统能力:** SystemCapability.Account.AppAccount 1049 1050**参数:** 1051 1052| 参数名 | 类型 | 必填 | 说明 | 1053| -------- | --------------------------- | ----- | ------------------------ | 1054| name | string | 是 | 应用账号的名称。 | 1055| key | string | 是 | 自定义数据的键名。 | 1056| callback | AsyncCallback<string> | 是 | 回调函数。当获取成功时,err为null,data为自定义数据的取值;否则为错误对象。 | 1057 1058**错误码:** 1059 1060| 错误码ID | 错误信息| 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**示例:** 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 1090根据指定键名获取特定应用账号的自定义数据。使用Promise异步回调。 1091 1092**系统能力:** SystemCapability.Account.AppAccount 1093 1094**参数:** 1095 1096| 参数名 | 类型 | 必填 | 说明 | 1097| ---- | ------ | ---- | --------- | 1098| name | string | 是 | 应用账号的名称。 | 1099| key | string | 是 | 自定义数据的键名。 | 1100 1101**返回值:** 1102 1103| 类型 | 说明 | 1104| --------------------- | --------------------- | 1105| Promise<string> | Promise对象,返回自定义数据的取值。 | 1106 1107**错误码:** 1108 1109| 错误码ID | 错误信息| 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**示例:** 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 1137根据指定键名获取特定应用账号的自定义数据。使用同步方式返回结果。 1138 1139**系统能力:** SystemCapability.Account.AppAccount 1140 1141**参数:** 1142 1143| 参数名 | 类型 | 必填 | 说明 | 1144| ---- | ------ | ---- | --------- | 1145| name | string | 是 | 应用账号的名称。 | 1146| key | string | 是 | 自定义数据的键名。 | 1147 1148**返回值:** 1149 1150| 类型 | 说明 | 1151| --------------------- | --------------------- | 1152| string | 自定义数据的取值。 | 1153 1154**错误码:** 1155 1156| 错误码ID | 错误信息| 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**示例:** 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 1179获取所有可访问的应用账号信息。使用callback异步回调。 1180 1181**系统能力:** SystemCapability.Account.AppAccount 1182 1183**参数:** 1184 1185| 参数名 | 类型 | 必填 | 说明 | 1186| -------- | ---------------------------------------- | ---- | --------- | 1187| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 回调函数。当查询成功时,err为null,data为获取到的应用账号信息列表;否则为错误对象。 | 1188 1189**错误码:** 1190 1191| 错误码ID | 错误信息| 1192| ------- | -------| 1193| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1194| 12300001 | System service exception. | 1195 1196**示例:** 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 1218获取所有可访问的应用账号信息。使用Promise异步回调。 1219 1220**系统能力:** SystemCapability.Account.AppAccount 1221 1222**返回值:** 1223 1224| 类型 | 说明 | 1225| ---------------------------------------- | --------------------- | 1226| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise对象,返回全部应用已授权账号信息对象。 | 1227 1228**错误码:** 1229 1230| 错误码ID | 错误信息| 1231| ------- | -------| 1232| 12300001 | System service exception. | 1233 1234**示例:** 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 1254根据应用账号所有者获取调用方可访问的应用账号列表。使用callback异步回调。 1255 1256**系统能力:** SystemCapability.Account.AppAccount 1257 1258**参数:** 1259 1260| 参数名 | 类型 | 必填 | 说明 | 1261| -------- | ---------------------------------------- | ---- | --------- | 1262| owner | string | 是 | 应用账号所有者的包名。 | 1263| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 回调函数。如果获取成功,err为null,data为获取到的应用账号列表;否则为错误对象。 | 1264 1265**错误码:** 1266 1267| 错误码ID | 错误信息| 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**示例:** 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 1297根据应用账号所有者获取调用方可访问的应用账号列表。使用Promise异步回调。 1298 1299**系统能力:** SystemCapability.Account.AppAccount 1300 1301**参数:** 1302 1303| 参数名 | 类型 | 必填 | 说明 | 1304| ----- | ------ | ---- | ------ | 1305| owner | string | 是 | 应用账号所有者的包名。 | 1306 1307**返回值:** 1308 1309| 类型 | 说明 | 1310| ---------------------------------------- | --------------------- | 1311| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise对象,返回获取到的应用账号列表。 | 1312 1313**错误码:** 1314 1315| 错误码ID | 错误信息| 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**示例:** 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 1343订阅指定应用的账号信息变更事件。 1344 1345**系统能力:** SystemCapability.Account.AppAccount 1346 1347**参数:** 1348 1349| 参数名 | 类型 | 必填 | 说明 | 1350| -------- | ---------------------------------------- | ---- | ------------------------------ | 1351| type | 'accountChange' | 是 | 事件回调类型,支持的事件为'accountChange',当目标应用更新账号信息时,触发该事件。 | 1352| owners | Array<string> | 是 | 应用账号所有者的包名列表。 | 1353| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 需要注册的回调函数,返回信息为发生变更的应用账号列表。 | 1354 1355**错误码:** 1356 1357| 错误码ID | 错误信息 | 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**示例:** 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 1381取消订阅账号信息变更事件。 1382 1383**系统能力:** SystemCapability.Account.AppAccount 1384 1385**参数:** 1386 1387| 参数名 | 类型 | 必填 | 说明 | 1388| -------- | -------------------------------- | ---- | ------------ | 1389| type | 'accountChange' | 是 | 事件回调类型,支持的事件为'accountChange',当账号所有者更新账号信息时,触发该事件。 | 1390| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | 否 | 需要注销的回调函数,默认为空,表示取消该类型事件所有的回调。 | 1391 1392**错误码:** 1393 1394| 错误码ID | 错误信息| 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**示例:** 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 1423对应用账号进行鉴权以获取授权令牌。使用callback异步回调。 1424 1425**系统能力:** SystemCapability.Account.AppAccount 1426 1427**参数:** 1428 1429| 参数名 | 类型 | 必填 | 说明 | 1430| -------- | --------------------- | ---- | --------------- | 1431| name | string | 是 | 应用账号的名称。 | 1432| owner | string | 是 | 应用账号所有者的包名。 | 1433| authType | string | 是 | 鉴权类型。 | 1434| callback | [AuthCallback](#authcallback9) | 是 | 回调对象,返回鉴权结果。 | 1435 1436**错误码:** 1437 1438| 错误码ID | 错误信息| 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**示例:** 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 1489对应用账号进行鉴权以获取授权令牌。使用callback异步回调。 1490 1491**系统能力:** SystemCapability.Account.AppAccount 1492 1493**参数:** 1494 1495| 参数名 | 类型 | 必填 | 说明 | 1496| -------- | --------------------- | ---- | --------------- | 1497| name | string | 是 | 应用账号的名称。 | 1498| owner | string | 是 | 应用账号所有者的包名。 | 1499| authType | string | 是 | 鉴权类型。 | 1500| options | Record<string, Object> | 是 | 鉴权所需的可选项。 | 1501| callback | [AuthCallback](#authcallback9) | 是 | 回调对象,返回鉴权结果。 | 1502 1503**错误码:** 1504 1505| 错误码ID | 错误信息| 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**示例:** 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 1559获取指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。 1560 1561**系统能力:** SystemCapability.Account.AppAccount 1562 1563**参数:** 1564 1565| 参数名 | 类型 | 必填 | 说明 | 1566| -------- | --------------------------- | ---- | ----------- | 1567| name | string | 是 | 应用账号的名称。 | 1568| owner | string | 是 | 应用账号所有者的包名。 | 1569| authType | string | 是 | 鉴权类型。 | 1570| callback | AsyncCallback<string> | 是 | 回调函数。当获取成功时,err为null,data为授权令牌值;否则为错误对象。 | 1571 1572**错误码:** 1573 1574| 错误码ID | 错误信息| 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**示例:** 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 1605获取指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。 1606 1607**系统能力:** SystemCapability.Account.AppAccount 1608 1609**参数:** 1610 1611| 参数名 | 类型 | 必填 | 说明 | 1612| -------- | ------ | ---- | ----------- | 1613| name | string | 是 | 应用账号的名称。 | 1614| owner | string | 是 | 应用账号所有者的包名。 | 1615| authType | string | 是 | 鉴权类型。 | 1616 1617**返回值:** 1618 1619| 类型 | 说明 | 1620| --------------------- | --------------------- | 1621| Promise<string> | Promise对象,返回授权令牌。 | 1622 1623**错误码:** 1624 1625| 错误码ID | 错误信息 | 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**示例:** 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 1653为指定应用账号设置特定鉴权类型的授权令牌。使用callback异步回调。 1654 1655**系统能力:** SystemCapability.Account.AppAccount 1656 1657**参数:** 1658 1659| 参数名 | 类型 | 必填 | 说明 | 1660| -------- | ------------------------- | ---- | -------- | 1661| name | string | 是 | 应用账号的名称。 | 1662| authType | string | 是 | 鉴权类型。 | 1663| token | string | 是 | 授权令牌。 | 1664| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为null;否则为错误对象。 | 1665 1666**错误码:** 1667 1668| 错误码ID | 错误信息| 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**示例:** 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 1698为指定应用账号设置特定鉴权类型的授权令牌。使用Promise异步回调。 1699 1700**系统能力:** SystemCapability.Account.AppAccount 1701 1702**参数:** 1703 1704| 参数名 | 类型 | 必填 | 说明 | 1705| -------- | ------ | ---- | -------- | 1706| name | string | 是 | 应用账号的名称。 | 1707| authType | string | 是 | 鉴权类型。 | 1708| token | string | 是 | 授权令牌。 | 1709 1710**返回值:** 1711 1712| 类型 | 说明 | 1713| ------------------- | --------------------- | 1714| Promise<void> | 无返回结果的Promise对象。 | 1715 1716**错误码:** 1717 1718| 错误码ID | 错误信息| 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**示例:** 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 1746删除指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。 1747 1748**系统能力:** SystemCapability.Account.AppAccount 1749 1750**参数:** 1751 1752| 参数名 | 类型 | 必填 | 说明 | 1753| -------- | ------------------------- | ---- | ------------ | 1754| name | string | 是 | 应用账号的名称。 | 1755| owner | string | 是 | 应用账号所有者的包名。 | 1756| authType | string | 是 | 鉴权类型。 | 1757| token | string | 是 | 授权令牌。 | 1758| callback | AsyncCallback<void> | 是 | 回调函数。当删除成功时,err为null;否则为错误对象。 | 1759 1760**错误码:** 1761 1762| 错误码ID | 错误信息 | 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**示例:** 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 1793删除指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。 1794 1795**系统能力:** SystemCapability.Account.AppAccount 1796 1797**参数:** 1798 1799| 参数名 | 类型 | 必填 | 说明 | 1800| -------- | ------ | ---- | ------------ | 1801| name | string | 是 | 应用账号的名称。 | 1802| owner | string | 是 | 应用账号所有者的包名。 | 1803| authType | string | 是 | 鉴权类型。 | 1804| token | string | 是 | 授权令牌。 | 1805 1806**返回值:** 1807 1808| 类型 | 说明 | 1809| ------------------- | --------------------- | 1810| Promise<void> | 无返回结果的Promise对象。 | 1811 1812**错误码:** 1813 1814| 错误码ID | 错误信息 | 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**示例:** 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 1842设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。 1843 1844**系统能力:** SystemCapability.Account.AppAccount 1845 1846**参数:** 1847 1848| 参数名 | 类型 | 必填 | 说明 | 1849| ---------- | ------------------------- | ---- | ------------------------- | 1850| name | string | 是 | 应用账号的名称。 | 1851| authType | string | 是 | 鉴权类型。 | 1852| bundleName | string | 是 | 被设置可见性的应用包名。 | 1853| isVisible | boolean | 是 | 是否可见。true表示可见,false表示不可见。 | 1854| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为null;否则为错误对象。| 1855 1856**错误码:** 1857 1858| 错误码ID | 错误信息| 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**示例:** 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 1891设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。 1892 1893**系统能力:** SystemCapability.Account.AppAccount 1894 1895**参数:** 1896 1897| 参数名 | 类型 | 必填 | 说明 | 1898| ---------- | ------------------------- | ---- | ------------------------- | 1899| name | string | 是 | 应用账号的名称。 | 1900| authType | string | 是 | 鉴权类型。 | 1901| bundleName | string | 是 | 被设置可见性的应用包名。 | 1902| isVisible | boolean | 是 | 是否可见。true表示可见,false表示不可见。 | 1903 1904**返回值:** 1905 1906| 类型 | 说明 | 1907| ------------------- | --------------------- | 1908| Promise<void> | 无返回结果的Promise对象。 | 1909 1910**错误码:** 1911 1912| 错误码ID | 错误信息| 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**示例:** 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 1942检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。 1943 1944**系统能力:** SystemCapability.Account.AppAccount 1945 1946**参数:** 1947 1948| 参数名 | 类型 | 必填 | 说明 | 1949| ---------- | ---------------------------- | ---- | ----------- | 1950| name | string | 是 | 应用账号的名称。 | 1951| authType | string | 是 | 鉴权类型。 | 1952| bundleName | string | 是 | 检查可见性的应用包名。 | 1953| callback | AsyncCallback<boolean> | 是 | 回调函数。当检查成功时,err为null,data为true表示可见,data为false表示不可见;否则为错误对象。 | 1954 1955**错误码:** 1956 1957| 错误码ID | 错误信息| 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**示例:** 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 1988检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。 1989 1990**系统能力:** SystemCapability.Account.AppAccount 1991 1992**参数:** 1993 1994| 参数名 | 类型 | 必填 | 说明 | 1995| ---------- | ------ | ---- | ------------- | 1996| name | string | 是 | 应用账号的名称。 | 1997| authType | string | 是 | 鉴权类型。 | 1998| bundleName | string | 是 | 用于检查可见性的应用包名。 | 1999 2000**返回值:** 2001 2002| 类型 | 说明 | 2003| ---------------------- | --------------------- | 2004| Promise<boolean> | Promise对象。返回true表示授权令牌对指定应用的可见,返回false表示不可见。 | 2005 2006**错误码:** 2007 2008| 错误码ID | 错误信息| 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**示例:** 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 2037获取指定账号对调用方可见的所有授权令牌。使用callback异步回调。 2038 2039**系统能力:** SystemCapability.Account.AppAccount 2040 2041**参数:** 2042 2043| 参数名 | 类型 | 必填 | 说明 | 2044| -------- | ---------------------------------------- | ---- | ----------- | 2045| name | string | 是 | 应用账号的名称。 | 2046| owner | string | 是 | 应用账号所有者的包名。 | 2047| callback | AsyncCallback<Array<[AuthTokenInfo](#authtokeninfo9)>> | 是 | 回调函数。当获取成功时,err为null,data为授权令牌数组;否则为错误对象。 | 2048 2049**错误码:** 2050 2051| 错误码ID | 错误信息| 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**示例:** 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 2081获取指定账号对调用方可见的所有授权令牌。使用Promise异步回调。 2082 2083**系统能力:** SystemCapability.Account.AppAccount 2084 2085**参数:** 2086 2087| 参数名 | 类型 | 必填 | 说明 | 2088| ----- | ------ | ---- | ----------- | 2089| name | string | 是 | 应用账号的名称。 | 2090| owner | string | 是 | 应用账号所有者的包名。 | 2091 2092**返回值:** 2093 2094| 类型 | 说明 | 2095| ---------------------------------------- | --------------------- | 2096| Promise<Array<[AuthTokenInfo](#authtokeninfo9)>> | Promise对象,返回授权令牌数组。 | 2097 2098**错误码:** 2099 2100| 错误码ID | 错误信息| 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**示例:** 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 2128获取指定应用账号的特定鉴权类型的授权列表,即被授权的包名数组(令牌的授权列表通过[setAuthTokenVisibility](#setauthtokenvisibility9)来设置)。使用callback异步回调。 2129 2130**系统能力:** SystemCapability.Account.AppAccount 2131 2132**参数:** 2133 2134| 参数名 | 类型 | 必填 | 说明 | 2135| -------- | ---------------------------------------- | ---- | ----------------------- | 2136| name | string | 是 | 应用账号的名称。 | 2137| authType | string | 是 | 鉴权类型。 | 2138| callback | AsyncCallback<Array<string>> | 是 | 回调函数。当获取成功时,err为null,data为被授权的包名数组;否则为错误对象。 | 2139 2140**错误码:** 2141 2142| 错误码ID | 错误信息| 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**示例:** 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 2172获取指定应用账号的特定鉴权类型的授权列表,即被授权的包名数组(令牌的授权列表通过[setAuthTokenVisibility](#setauthtokenvisibility9)来设置)。使用Promise异步回调。 2173 2174**系统能力:** SystemCapability.Account.AppAccount 2175 2176**参数:** 2177 2178| 参数名 | 类型 | 必填 | 说明 | 2179| -------- | ------ | ---- | ------------------------------ | 2180| name | string | 是 | 应用账号的名称。 | 2181| authType | string | 是 | 鉴权类型。 | 2182 2183**返回值:** 2184 2185| 类型 | 说明 | 2186| ---------------------------------- | --------------------- | 2187| Promise<Array<string>> | Promise对象,返回被授权的包名数组。 | 2188 2189**错误码:** 2190 2191| 错误码ID | 错误信息| 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**示例:** 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 2219获取鉴权会话的认证器回调对象。使用callback异步回调。 2220 2221**系统能力:** SystemCapability.Account.AppAccount 2222 2223**参数:** 2224 2225| 参数名 | 类型 | 必填 | 说明 | 2226| --------- | ---------------------------------------- | ---- | -------- | 2227| sessionId | string | 是 | 鉴权会话的标识。 | 2228| callback | AsyncCallback<[AuthCallback](#authcallback9)> | 是 | 回调函数。当获取成功时,err为null,data为鉴权会话的认证器回调对象;否则为错误对象。 | 2229 2230**错误码:** 2231 2232| 错误码ID | 错误信息 | 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**示例:** 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 生命周期函数 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 2277获取鉴权会话的认证器回调对象。使用Promise异步回调。 2278 2279**系统能力:** SystemCapability.Account.AppAccount 2280 2281**参数:** 2282 2283| 参数名 | 类型 | 必填 | 说明 | 2284| --------- | ------ | ---- | -------- | 2285| sessionId | string | 是 | 鉴权会话的标识。 | 2286 2287**返回值:** 2288 2289| 类型 | 说明 | 2290| ------------------------------------ | --------------------- | 2291| Promise<[AuthCallback](#authcallback9)> | Promise对象,返回鉴权会话的认证器回调对象。 | 2292 2293**错误码:** 2294 2295| 错误码ID | 错误信息 | 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**示例:** 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 生命周期函数 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 2338获取指定应用的认证器信息。使用callback异步回调。 2339 2340**系统能力:** SystemCapability.Account.AppAccount 2341 2342**参数:** 2343 2344| 参数名 | 类型 | 必填 | 说明 | 2345| -------- | -------------------------------------- | ---- | ----------- | 2346| owner | string | 是 | 应用账号所有者的包名。 | 2347| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | 是 | 回调函数。当获取成功时,err为null,data为认证器信息对象;否则为错误对象。 | 2348 2349**错误码:** 2350 2351| 错误码ID | 错误信息| 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**示例:** 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 2381获取指定应用的认证器信息。使用Promise异步回调。 2382 2383**系统能力:** SystemCapability.Account.AppAccount 2384 2385**参数:** 2386 2387| 参数名 | 类型 | 必填 | 说明 | 2388| ----- | ------ | ---- | ----------- | 2389| owner | string | 是 | 应用账号所有者的包名。 | 2390 2391**返回值:** 2392 2393| 类型 | 说明 | 2394| -------------------------------- | --------------------- | 2395| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise对象,返回指定应用的认证器信息对象。 | 2396 2397**错误码:** 2398 2399| 错误码ID | 错误信息| 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**示例:** 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 2427检查指定应用账号是否满足特定的标签集合。使用callback异步回调。该方法依赖目标应用的认证器提供标签检查的能力。 2428 2429**系统能力:** SystemCapability.Account.AppAccount 2430 2431**参数:** 2432 2433| 参数名 | 类型 | 必填 | 说明 | 2434| -------------- | ------------------------- | ----- | --------------- | 2435| name | string | 是 | 应用账号的名称。 | 2436| owner | string | 是 | 应用账号所有者的包名。| 2437| labels | Array<string> | 是 | 标签数组。 | 2438| callback | AsyncCallback<boolean> | 是 | 回调函数。当检查成功时,err为null,data为true表示满足特定的标签集合,data为false表示不满足;否则为错误对象。 | 2439 2440**错误码:** 2441 2442| 错误码ID | 错误信息 | 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**示例:** 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 2476检查指定应用账号是否满足特定的标签集合。使用Promise异步回调。该方法依赖目标应用的认证器提供标签检查的能力。 2477 2478**系统能力:** SystemCapability.Account.AppAccount 2479 2480**参数:** 2481 2482| 参数名 | 类型 | 必填 | 说明 | 2483| -------------- | ------------------------- | ----- | --------------- | 2484| name | string | 是 | 应用账号的名称。 | 2485| owner | string | 是 | 应用账号所有者的包名。| 2486| labels | Array<string> | 是 | 标签数组。 | 2487 2488**返回值:** 2489 2490| 类型 | 说明 | 2491| ------------------- | -------------------------------- | 2492| Promise<boolean> | Promise对象。返回true表示指定账号满足特定的标签集合,返回false表示不满足。 | 2493 2494**错误码:** 2495 2496| 错误码ID | 错误信息 | 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**示例:** 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 2528删除指定应用账号的特定类型的凭据信息。使用callback异步回调。 2529 2530**系统能力:** SystemCapability.Account.AppAccount 2531 2532**参数:** 2533 2534| 参数名 | 类型 | 必填 | 说明 | 2535| -------------- | ------------------------- | ----- | -------------- | 2536| name | string | 是 | 应用账号的名称。 | 2537| credentialType | string | 是 | 凭据类型。 | 2538| callback | AsyncCallback<void> | 是 | 回调函数。当删除成功时,err为null;否则为错误对象。 | 2539 2540**错误码:** 2541 2542| 错误码ID | 错误信息 | 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**示例:** 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 2572删除指定应用账号的特定类型的凭据信息。使用Promise异步回调。 2573 2574**系统能力:** SystemCapability.Account.AppAccount 2575 2576**参数:** 2577 2578| 参数名 | 类型 | 必填 | 说明 | 2579| -------------- | ------ | ----- | --------------- | 2580| name | string | 是 | 应用账号的名称。 | 2581| credentialType | string | 是 | 凭据类型。 | 2582 2583**返回值:** 2584 2585| 类型 | 说明 | 2586| ------------------- | -------------------------------- | 2587| Promise<void> | 无返回结果的Promise对象。 | 2588 2589**错误码:** 2590 2591| 错误码ID | 错误信息 | 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**示例:** 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 2619根据选项选择调用方可访问的账号列表。使用callback异步回调。如果选项中包含标签约束,则该方法依赖目标应用的认证器提供标签检查的能力。 2620 2621**系统能力:** SystemCapability.Account.AppAccount 2622 2623**参数:** 2624 2625| 参数名 | 类型 | 必填 | 说明 | 2626| -------------- | ----------------------------------- | ----- | --------------- | 2627| options | [SelectAccountsOptions](#selectaccountsoptions9) | 是 | 选择账号的选项。 | 2628| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 回调函数。当根据选项选择请求方可访问的账号列表时,err为null,data为可访问的账号信息对象;否则为错误对象。 | 2629 2630**错误码:** 2631 2632| 错误码ID | 错误信息 | 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**示例:** 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 2667根据选项选择调用方可访问的账号列表。使用Promise异步回调。如果选项中包含标签约束,则该方法依赖目标应用的认证器提供标签检查的能力。 2668 2669**系统能力:** SystemCapability.Account.AppAccount 2670 2671**参数:** 2672 2673| 参数名 | 类型 | 必填 | 说明 | 2674| -------------- | ------------------------- | ----- | --------------- | 2675| options | [SelectAccountsOptions](#selectaccountsoptions9) | 是 | 选择账号的选项。 | 2676 2677**返回值:** 2678 2679| 类型 | 说明 | 2680| ------------------- | -------------------------------- | 2681| Promise<[AppAccountInfo](#appaccountinfo)> | Promise对象,返回调用方可访问的账号列表。 | 2682 2683**错误码:** 2684 2685| 错误码ID | 错误信息 | 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**示例:** 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 2716验证指定账号的凭据。使用callback异步回调。 2717 2718**系统能力:** SystemCapability.Account.AppAccount 2719 2720**参数:** 2721 2722| 参数名 | 类型 | 必填 | 说明 | 2723| -------- | --------------------- | ----- | ----------------------- | 2724| name | string | 是 | 应用账号的名称。 | 2725| owner | string | 是 | 应用账号所有者的包名。 | 2726| callback | [AuthCallback](#authcallback9) | 是 | 回调函数,返回验证结果。 | 2727 2728**错误码:** 2729 2730| 错误码ID | 错误信息| 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**示例:** 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 2764验证用户凭据。使用callback异步回调。 2765 2766**系统能力:** SystemCapability.Account.AppAccount 2767 2768**参数:** 2769 2770| 参数名 | 类型 | 必填 | 说明 | 2771| -------- | ----------------------- | ----- | ----------------------- | 2772| name | string | 是 | 应用账号的名称。 | 2773| owner | string | 是 | 应用账号所有者的包名。 | 2774| options | [VerifyCredentialOptions](#verifycredentialoptions9) | 是 | 验证凭据的选项。 | 2775| callback | [AuthCallback](#authcallback9) | 是 | 回调函数,返回验证结果。 | 2776 2777**错误码:** 2778 2779| 错误码ID | 错误信息| 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**示例:** 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 2817设置指定应用的认证器属性。使用callback异步回调。 2818 2819**系统能力:** SystemCapability.Account.AppAccount 2820 2821**参数:** 2822 2823| 参数名 | 类型 | 必填 | 说明 | 2824| -------- | --------------------- | ----- | ----------------------- | 2825| owner | string | 是 | 认证器的所有者的包名。 | 2826| callback | [AuthCallback](#authcallback9) | 是 | 回调函数,返回设置属性的结果。 | 2827 2828**错误码:** 2829 2830| 错误码ID | 错误信息 | 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**示例:** 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 2863设置认证器属性。使用callback异步回调。 2864 2865**系统能力:** SystemCapability.Account.AppAccount 2866 2867**参数:** 2868 2869| 参数名 | 类型 | 必填 | 说明 | 2870| -------- | --------------------- | ----- | ----------------------- | 2871| owner | string | 是 | 认证器的所有者的包名。 | 2872| options | [SetPropertiesOptions](#setpropertiesoptions9) | 是 | 设置属性的选项。 | 2873| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调,返回设置属性的结果。 | 2874 2875**错误码:** 2876 2877| 错误码ID | 错误信息 | 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**示例:** 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 2914根据账号名添加应用账号。使用callback异步回调。 2915 2916> **说明:** 2917> 2918>从 API version 7开始支持,从API version 9开始废弃。建议使用[createAccount](#createaccount9)替代。 2919 2920 2921**系统能力:** SystemCapability.Account.AppAccount 2922 2923**参数:** 2924 2925| 参数名 | 类型 | 必填 | 说明 | 2926| -------- | ------------------------- | ---- | -------------------- | 2927| name | string | 是 | 应用账号的名称。 | 2928| callback | AsyncCallback<void> | 是 | 回调函数。当创建成功时,err为null,否则为错误对象。 | 2929 2930**示例:** 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 2944根据账号名和额外信息添加应用账号。使用callback异步回调。 2945 2946> **说明:** 2947> 从 API version 7开始支持,从API version 9开始废弃。建议使用[createAccount](#createaccount9-1)替代。 2948 2949**系统能力:** SystemCapability.Account.AppAccount 2950 2951**参数:** 2952 2953| 参数名 | 类型 | 必填 | 说明 | 2954| --------- | ------------------------- | ---- | ---------------------------------------- | 2955| name | string | 是 | 应用账号的名称。 | 2956| extraInfo | string | 是 | 额外信息(能转换string类型的其它信息),额外信息不能是应用账号的敏感信息(如应用账号密码、token等)。 | 2957| callback | AsyncCallback<void> | 是 | 回调函数。当创建成功时,err为null,否则为错误对象。 | 2958 2959**示例:** 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 2973根据账号名和额外信息添加应用账号。使用callback异步回调。使用Promise异步回调。 2974 2975> **说明:** 2976> 从 API version 7开始支持,从API version 9开始废弃。建议使用[createAccount](#createaccount9-2)替代。 2977 2978**系统能力:** SystemCapability.Account.AppAccount 2979 2980**参数:** 2981 2982| 参数名 | 类型 | 必填 | 说明 | 2983| --------- | ------ | ---- | ---------------------------------------- | 2984| name | string | 是 | 应用账号的名称。 | 2985| extraInfo | string | 否 | 额外信息(能转换string类型的其它信息),额外信息不能是应用账号的敏感信息(如应用账号密码、token等),默认为空,表示创建的该账号无额外信息需要添加。 | 2986 2987**返回值:** 2988 2989| 类型 | 说明 | 2990| ------------------- | --------------------- | 2991| Promise<void> | 无返回结果的Promise对象。 | 2992 2993**示例:** 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 3009根据指定的账号所有者隐式地添加应用账号。使用callback异步回调。 3010 3011> **说明:** 3012> 3013> 从 API version 8开始支持,从API version 9开始废弃。建议使用[createAccountImplicitly](#createaccountimplicitly9)替代。 3014 3015**系统能力:** SystemCapability.Account.AppAccount 3016 3017**参数:** 3018 3019| 参数名 | 类型 | 必填 | 说明 | 3020| -------- | --------------------- | ---- | ----------------------- | 3021| owner | string | 是 | 应用账号所有者的包名。 | 3022| authType | string | 是 | 鉴权类型。鉴权类型为自定义。 | 3023| options | {[key: string]: any} | 是 | 鉴权所需要的可选项。可选项可根据自己需要设置。 | 3024| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | 是 | 认证器回调对象,返回添加结果。 | 3025 3026**示例:** 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 3063删除应用账号。使用callback异步回调。 3064 3065> **说明:** 3066> 3067> 从 API version 7开始支持,从API version 9开始废弃。建议使用[removeAccount](#removeaccount9)替代。 3068 3069**系统能力:** SystemCapability.Account.AppAccount 3070 3071**参数:** 3072 3073| 参数名 | 类型 | 必填 | 说明 | 3074| -------- | ------------------------- | ---- | ---------------- | 3075| name | string | 是 | 应用账号的名称。 | 3076| callback | AsyncCallback<void> | 是 | 回调函数。当删除成功时,err为null,否则为错误对象。 | 3077 3078**示例:** 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 3092删除应用账号。使用Promise异步回调。 3093 3094> **说明:** 3095> 3096> 从 API version 7开始支持,从API version 9开始废弃。建议使用[removeAccount](#removeaccount9)替代。 3097 3098**系统能力:** SystemCapability.Account.AppAccount 3099 3100**参数:** 3101 3102| 参数名 | 类型 | 必填 | 说明 | 3103| ---- | ------ | ---- | ----------- | 3104| name | string | 是 | 应用账号的名称。 | 3105 3106**返回值:** 3107 3108| 类型 | 说明 | 3109| :------------------ | :-------------------- | 3110| Promise<void> | 无返回结果的Promise对象。 | 3111 3112**示例:** 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 3127禁止指定第三方应用账号名称对指定的第三方应用进行访问。使用callback异步回调。 3128 3129> **说明:** 3130> 3131> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setAppAccess](#setappaccess9)替代。 3132 3133**系统能力:** SystemCapability.Account.AppAccount 3134 3135**参数:** 3136 3137| 参数名 | 类型 | 必填 | 说明 | 3138| ---------- | ------------------------- | ---- | --------------------------------- | 3139| name | string | 是 | 应用账号的名称。 | 3140| bundleName | string | 是 | 第三方应用的包名。 | 3141| callback | AsyncCallback<void> | 是 | 回调函数。当禁止指定第三方应用账号名称对指定包名称的第三方应用进行访问设置成功时,err为null,否则为错误对象。 | 3142 3143**示例:** 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 3157禁止指定第三方应用账号名称对指定包名称的第三方应用进行访问。使用Promise异步回调。 3158 3159> **说明:** 3160> 3161> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setAppAccess](#setappaccess9-1)替代。 3162 3163**系统能力:** SystemCapability.Account.AppAccount 3164 3165**参数:** 3166 3167| 参数名 | 类型 | 必填 | 说明 | 3168| ---------- | ------ | ---- | ---------------- | 3169| name | string | 是 | 要禁用访问的第三方应用账号的名称。 | 3170| bundleName | string | 是 | 第三方应用的包名。 | 3171 3172**返回值:** 3173 3174| 类型 | 说明 | 3175| :------------------ | :-------------------- | 3176| Promise<void> | 无返回结果的Promise对象。 | 3177 3178**示例:** 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 3194允许指定第三方应用账号名称对指定包名称的第三方应用进行访问。使用callback异步回调。 3195 3196> **说明:** 3197> 3198> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setAppAccess](#setappaccess9)替代。 3199 3200**系统能力:** SystemCapability.Account.AppAccount 3201 3202**参数:** 3203 3204| 参数名 | 类型 | 必填 | 说明 | 3205| ---------- | ------------------------- | ---- | --------------------------------- | 3206| name | string | 是 | 应用账号的名称。 | 3207| bundleName | string | 是 | 第三方应用的包名。 | 3208| callback | AsyncCallback<void> | 是 | 回调函数。当允许指定第三方应用账号名称对指定包名称的第三方应用进行访问设置成功时,err为null,否则为错误对象。 | 3209 3210**示例:** 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 3224允许指定第三方应用账号的名称对指定包名称的第三方应用进行访问。使用Promise异步回调。 3225 3226> **说明:** 3227> 3228> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setAppAccess](#setappaccess9-1)替代。 3229 3230**系统能力:** SystemCapability.Account.AppAccount 3231 3232**参数:** 3233 3234| 参数名 | 类型 | 必填 | 说明 | 3235| ---------- | ------ | ---- | --------- | 3236| name | string | 是 | 应用账号的名称。 | 3237| bundleName | string | 是 | 第三方应用的包名。 | 3238 3239**返回值:** 3240 3241| 类型 | 说明 | 3242| :------------------ | :-------------------- | 3243| Promise<void> | 无返回结果的Promise对象。 | 3244 3245**示例:** 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 3261检查指定应用账号是否开启数据同步功能。使用callback异步回调。 3262 3263> **说明:** 3264> 3265> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkDataSyncEnabled](#checkdatasyncenabled9)替代。 3266 3267**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 3268 3269**系统能力:** SystemCapability.Account.AppAccount 3270 3271**参数:** 3272 3273| 参数名 | 类型 | 必填 | 说明 | 3274| -------- | ---------------------------- | ---- | --------------------- | 3275| name | string | 是 | 应用账号的名称。 | 3276| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定应用账号已开启数据同步功能;返回false表示未开启。 | 3277 3278**示例:** 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 3293检查指定应用账号是否开启数据同步功能。使用Promise异步回调。 3294 3295> **说明:** 3296> 3297> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkDataSyncEnabled](#checkdatasyncenabled9-1)替代。 3298 3299**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 3300 3301**系统能力:** SystemCapability.Account.AppAccount 3302 3303**参数:** 3304 3305| 参数名 | 类型 | 必填 | 说明 | 3306| ---- | ------ | ---- | ------- | 3307| name | string | 是 | 应用账号的名称。 | 3308 3309**返回值:** 3310 3311| 类型 | 说明 | 3312| ---------------------- | --------------------- | 3313| Promise<boolean> | Promise对象。返回true表示指定应用账号已开启数据同步功能;返回false表示未开启。 | 3314 3315**示例:** 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 3331设置指定应用账号的凭据。使用callback异步回调。 3332 3333> **说明:** 3334> 3335> 从 API version 7开始支持,从API version 9开始废弃,建议使用[setCredential](#setcredential9)替代。 3336 3337**系统能力:** SystemCapability.Account.AppAccount 3338 3339**参数:** 3340 3341| 参数名 | 类型 | 必填 | 说明 | 3342| -------------- | ------------------------- | ---- | ------------- | 3343| name | string | 是 | 应用账号的名称。 | 3344| credentialType | string | 是 | 凭据类型。 | 3345| credential | string | 是 | 凭据取值。 | 3346| callback | AsyncCallback<void> | 是 | 回调函数。当设置此应用程序账号的凭据成功时,err为null,否则为错误对象。 | 3347 3348**示例:** 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 3362设置指定应用账号的凭据。使用Promise异步回调。 3363 3364> **说明:** 3365> 3366> 从 API version 7开始支持,从API version 9开始废弃,建议使用[setCredential](#setcredential9-1)替代。 3367 3368**系统能力:** SystemCapability.Account.AppAccount 3369 3370**参数:** 3371 3372| 参数名 | 类型 | 必填 | 说明 | 3373| -------------- | ------ | ---- | ---------- | 3374| name | string | 是 | 应用账号的名称。 | 3375| credentialType | string | 是 | 凭据类型。 | 3376| credential | string | 是 | 凭据取值。 | 3377 3378**返回值:** 3379 3380| 类型 | 说明 | 3381| :------------------ | :-------------------- | 3382| Promise<void> | 无返回结果的Promise对象。 | 3383 3384**示例:** 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 3400设置指定应用账号的额外信息。使用callback异步回调。 3401 3402> **说明:** 3403> 3404> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setCustomData](#setcustomdata9)替代。 3405 3406 3407**系统能力:** SystemCapability.Account.AppAccount 3408 3409**参数:** 3410 3411| 参数名 | 类型 | 必填 | 说明 | 3412| --------- | ------------------------- | ---- | --------------- | 3413| name | string | 是 | 应用账号的名称。 | 3414| extraInfo | string | 是 | 额外信息(能转换string类型的其它信息),额外信息不能是应用账号的敏感信息(如应用账号密码、token等)。 | 3415| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为null,否则为错误对象。 | 3416 3417**示例:** 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 3431设置此应用程序账号的额外信息。使用Promise异步回调。 3432 3433> **说明:** 3434> 3435> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setCustomData](#setcustomdata9-1)替代。 3436 3437 3438**系统能力:** SystemCapability.Account.AppAccount 3439 3440**参数:** 3441 3442| 参数名 | 类型 | 必填 | 说明 | 3443| --------- | ------ | ---- | --------- | 3444| name | string | 是 | 应用账号的名称。 | 3445| extraInfo | string | 是 | 额外信息(能转换string类型的其它信息),额外信息不能是应用账号的敏感信息(如应用账号密码、token等)。 | 3446 3447**返回值:** 3448 3449| 类型 | 说明 | 3450| :------------------ | :-------------------- | 3451| Promise<void> | 无返回结果的Promise对象。 | 3452 3453**示例:** 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 3469开启或禁止指定应用账号的数据同步功能。使用callback异步回调。 3470 3471> **说明:** 3472> 3473> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setDataSyncEnabled](#setdatasyncenabled9)替代。 3474 3475**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 3476 3477**系统能力:** SystemCapability.Account.AppAccount 3478 3479**参数:** 3480 3481| 参数名 | 类型 | 必填 | 说明 | 3482| -------- | ------------------------- | ---- | ------------------------- | 3483| name | string | 是 | 应用账号的名称。 | 3484| isEnable | boolean | 是 | 是否开启数据同步。 | 3485| callback | AsyncCallback<void> | 是 | 回调函数。当开启或禁止成功时,err为null,否则为错误对象。 | 3486 3487**示例:** 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 3501开启或禁止指定应用账号的数据同步功能。使用Promise异步回调。 3502 3503> **说明:** 3504> 3505> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setDataSyncEnabled](#setdatasyncenabled9-1)替代。 3506 3507**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 3508 3509**系统能力:** SystemCapability.Account.AppAccount 3510 3511**参数:** 3512 3513| 参数名 | 类型 | 必填 | 说明 | 3514| -------- | ------- | ---- | ----------- | 3515| name | string | 是 | 应用账号的名称。 | 3516| isEnable | boolean | 是 | 是否开启数据同步。 | 3517 3518**返回值:** 3519 3520| 类型 | 说明 | 3521| :------------------ | :-------------------- | 3522| Promise<void> | 无返回结果的Promise对象。 | 3523 3524**示例:** 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 3540设置指定应用账号的关联数据。使用callback异步回调。 3541 3542> **说明:** 3543> 3544> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setCustomData](#setcustomdata9)替代。 3545 3546 3547**系统能力:** SystemCapability.Account.AppAccount 3548 3549**参数:** 3550 3551| 参数名 | 类型 | 必填 | 说明 | 3552| -------- | ------------------------- | ---- | ----------------- | 3553| name | string | 是 | 应用账号的名称。 | 3554| key | string | 是 | 关联数据的键名。 | 3555| value | string | 是 | 关联数据的取值。 | 3556| callback | AsyncCallback<void> | 是 | 回调函数。当设置与此应用账号关联的数据成功时,err为null,否则为错误对象。 | 3557 3558**示例:** 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 3572设置指定应用账号的关联数据。使用Promise异步回调。 3573 3574> **说明:** 3575> 3576> 从 API version 7开始支持,从API version 9开始废弃。建议使用[setCustomData](#setcustomdata9-1)替代。 3577 3578 3579**系统能力:** SystemCapability.Account.AppAccount 3580 3581**参数:** 3582 3583| 参数名 | 类型 | 必填 | 说明 | 3584| ----- | ------ | ---- | ----------------- | 3585| name | string | 是 | 应用账号的名称。 | 3586| key | string | 是 | 关联数据的键名。 | 3587| value | string | 是 | 关联数据的取值。 | 3588 3589**返回值:** 3590 3591| 类型 | 说明 | 3592| :------------------ | :-------------------- | 3593| Promise<void> | 无返回结果的Promise对象。 | 3594 3595**示例:** 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 3611获取所有可访问的应用账号信息。使用callback异步回调。 3612 3613> **说明:** 3614> 3615> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getAllAccounts](#getallaccounts9)替代。 3616 3617**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,该权限仅系统应用可申请。 3618 3619**系统能力:** SystemCapability.Account.AppAccount 3620 3621**参数:** 3622 3623| 参数名 | 类型 | 必填 | 说明 | 3624| -------- | ---------------------------------------- | ---- | --------- | 3625| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 回调函数。当查询成功时,err为null,data为获取到的应用账号信息列表;否则为错误对象。 | 3626 3627**示例:** 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 3642获取所有可访问的应用账号信息。使用Promise异步回调。 3643 3644> **说明:** 3645> 3646> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getAllAccounts](#getallaccounts9-1)替代。 3647 3648**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,该权限仅系统应用可申请。 3649 3650**系统能力:** SystemCapability.Account.AppAccount 3651 3652**返回值:** 3653 3654| 类型 | 说明 | 3655| ---------------------------------------- | --------------------- | 3656| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise对象,返回全部应用已授权账号信息对象。 | 3657 3658**示例:** 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 3674根据应用账号所有者获取调用方可访问的应用账号列表。使用callback异步回调。 3675 3676> **说明:** 3677> 3678> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getAccountsByOwner](#getaccountsbyowner9)替代。 3679 3680**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,该权限仅系统应用可申请。 3681 3682**系统能力:** SystemCapability.Account.AppAccount 3683 3684**参数:** 3685 3686| 参数名 | 类型 | 必填 | 说明 | 3687| -------- | ---------------------------------------- | ---- | --------- | 3688| owner | string | 是 | 应用账号所有者的包名。 | 3689| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 应用账号信息列表。 | 3690 3691**示例:** 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 3707根据应用账号所有者获取调用方可访问的应用账号列表。使用Promise异步回调。 3708 3709> **说明:** 3710> 3711> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getAccountsByOwner](#getaccountsbyowner9-1)替代。 3712 3713**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,该权限仅系统应用可申请。 3714 3715**系统能力:** SystemCapability.Account.AppAccount 3716 3717**参数:** 3718 3719| 参数名 | 类型 | 必填 | 说明 | 3720| ----- | ------ | ---- | ------ | 3721| owner | string | 是 | 应用账号所有者的包名。 | 3722 3723**返回值:** 3724 3725| 类型 | 说明 | 3726| ---------------------------------------- | --------------------- | 3727| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise对象,返回指定应用全部账号信息对象。 | 3728 3729**示例:** 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 3746获取指定应用账号的凭据。使用callback异步回调。 3747 3748> **说明:** 3749> 3750> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCredential](#getcredential9)替代。 3751 3752**系统能力:** SystemCapability.Account.AppAccount 3753 3754**参数:** 3755 3756| 参数名 | 类型 | 必填 | 说明 | 3757| -------------- | --------------------------- | ---- | -------------- | 3758| name | string | 是 | 应用账号的名称。 | 3759| credentialType | string | 是 | 凭据类型。 | 3760| callback | AsyncCallback<string> | 是 | 回调函数。当获取凭据成功时,err为null,data为指定应用账号的凭据;否则为错误对象。 | 3761 3762**示例:** 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 3777获取指定应用账号的凭据。使用Promise异步回调。 3778 3779> **说明:** 3780> 3781> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCredential](#getcredential9-1)替代。 3782 3783**系统能力:** SystemCapability.Account.AppAccount 3784 3785**参数:** 3786 3787| 参数名 | 类型 | 必填 | 说明 | 3788| -------------- | ------ | ---- | ---------- | 3789| name | string | 是 | 应用账号的名称。 | 3790| credentialType | string | 是 | 凭据类型。 | 3791 3792**返回值:** 3793 3794| 类型 | 说明 | 3795| :-------------------- | :-------------------- | 3796| Promise<string> | Promise对象,返回指定应用账号的凭据。 | 3797 3798**示例:** 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 3814获取指定应用账号的额外信息(能转换成string类型的其它信息)。使用callback异步回调。 3815 3816> **说明:** 3817> 3818> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCustomData](#getcustomdata9)替代。 3819 3820**系统能力:** SystemCapability.Account.AppAccount 3821 3822**参数:** 3823 3824| 参数名 | 类型 | 必填 | 说明 | 3825| -------- | --------------------------- | ---- | --------------- | 3826| name | string | 是 | 应用账号的名称。 | 3827| callback | AsyncCallback<string> | 是 | 回调函数。当获取此应用账号的额外信息成功时,err为null,data返回此应用账号的额外信息对象;否则为错误对象。 | 3828 3829**示例:** 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 3844获取指定应用账号的额外信息(能转换成string类型的其它信息)。使用Promise异步回调。 3845 3846> **说明:** 3847> 3848> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCustomData](#getcustomdata9-1)替代。 3849 3850**系统能力:** SystemCapability.Account.AppAccount 3851 3852**参数:** 3853 3854| 参数名 | 类型 | 必填 | 说明 | 3855| ---- | ------ | ---- | ------- | 3856| name | string | 是 | 应用账号的名称。 | 3857 3858**返回值:** 3859 3860| 类型 | 说明 | 3861| :-------------------- | :-------------------- | 3862| Promise<string> | Promise对象,返回此应用程序账号的额外信息对象。 | 3863 3864**示例:** 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 3880根据指定键名获取特定应用账号的关联数据。使用callback异步回调。 3881 3882> **说明:** 3883> 3884> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCustomData](#getcustomdata9)替代。 3885 3886**系统能力:** SystemCapability.Account.AppAccount 3887 3888**参数:** 3889 3890| 参数名 | 类型 | 必填 | 说明 | 3891| -------- | --------------------------- | ---- | ----------------- | 3892| name | string | 是 | 应用账号的名称。 | 3893| key | string | 是 | 关联数据的键名。 | 3894| callback | AsyncCallback<string> | 是 | 回调函数。当获取成功时,err为null,data为关联数据的取值;否则为错误对象。 | 3895 3896**示例:** 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 3911获取与此应用程序账号关联的数据。使用Promise异步回调。 3912 3913> **说明:** 3914> 3915> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCustomData](#getcustomdata9-1)替代。 3916 3917**系统能力:** SystemCapability.Account.AppAccount 3918 3919**参数:** 3920 3921| 参数名 | 类型 | 必填 | 说明 | 3922| ---- | ------ | ---- | --------- | 3923| name | string | 是 | 应用账号的名称。 | 3924| key | string | 是 | 关联数据的键名。 | 3925 3926**返回值:** 3927 3928| 类型 | 说明 | 3929| :-------------------- | :-------------------- | 3930| Promise<string> | Promise对象,返回关联数据的取值。 | 3931 3932**示例:** 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 3948订阅指定应用的账号信息变更事件。 3949 3950> **说明:** 3951> 3952> 从 API version 7开始支持,从API version 9开始废弃。建议使用[on('accountChange')](#onaccountchange9)替代。 3953 3954**系统能力:** SystemCapability.Account.AppAccount 3955 3956**参数:** 3957 3958| 参数名 | 类型 | 必填 | 说明 | 3959| -------- | ---------------------------------------- | ---- | ------------------------------ | 3960| type | 'change' | 是 | 事件回调类型,支持的事件为'change',当账号所有者更新账号信息时,触发该事件。 | 3961| owners | Array<string> | 是 | 应用账号所有者的包名列表。 | 3962| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | 是 | 需要注册的回调函数,返回信息发生变更的应用账号列表。 | 3963 3964**示例:** 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 3982取消订阅账号信息变更事件。 3983 3984> **说明:** 3985> 3986> 从 API version 7开始支持,从API version 9开始废弃。建议使用[off('accountChange')](#offaccountchange9)替代。 3987 3988**系统能力:** SystemCapability.Account.AppAccount 3989 3990**参数:** 3991 3992| 参数名 | 类型 | 必填 | 说明 | 3993| -------- | -------------------------------- | ---- | ------------ | 3994| type | 'change' | 是 | 事件回调类型,支持的事件为'change',当账号所有者更新账号信息时,触发该事件。 | 3995| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | 否 | 需要注销的回调函数,默认为空,表示取消该类型事件的所有回调。 | 3996 3997**示例:** 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 4018对应用账号进行鉴权以获取授权令牌。使用callback异步回调。 4019 4020> **说明:** 4021> 4022> 从 API version 8开始支持,从API version 9开始废弃。建议使用[auth](#auth9)替代。 4023 4024**系统能力:** SystemCapability.Account.AppAccount 4025 4026**参数:** 4027 4028| 参数名 | 类型 | 必填 | 说明 | 4029| -------- | --------------------- | ---- | --------------- | 4030| name | string | 是 | 应用账号的名称。 | 4031| owner | string | 是 | 应用账号所有者的包名。 | 4032| authType | string | 是 | 鉴权类型。 | 4033| options | {[key: string]: any} | 是 | 鉴权所需的可选项。 | 4034| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | 是 | 回调对象,返回鉴权结果。 | 4035 4036**示例:** 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 4073获取指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。 4074 4075> **说明:** 4076> 4077> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthToken](#getauthtoken9)替代。 4078 4079**系统能力:** SystemCapability.Account.AppAccount 4080 4081**参数:** 4082 4083| 参数名 | 类型 | 必填 | 说明 | 4084| -------- | --------------------------- | ---- | ----------- | 4085| name | string | 是 | 应用账号的名称。 | 4086| owner | string | 是 | 应用账号所有者的包名。 | 4087| authType | string | 是 | 鉴权类型。 | 4088| callback | AsyncCallback<string> | 是 | 回调函数。当获取成功时,err为null,data为授权令牌值;否则为错误对象。 | 4089 4090**示例:** 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 4106获取指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。 4107 4108> **说明:** 4109> 4110> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthToken](#getauthtoken9-1)替代。 4111 4112**系统能力:** SystemCapability.Account.AppAccount 4113 4114**参数:** 4115 4116| 参数名 | 类型 | 必填 | 说明 | 4117| -------- | ------ | ---- | ----------- | 4118| name | string | 是 | 应用账号的名称。 | 4119| owner | string | 是 | 应用账号所有者的包名。 | 4120| authType | string | 是 | 鉴权类型。 | 4121 4122**返回值:** 4123 4124| 类型 | 说明 | 4125| --------------------- | --------------------- | 4126| Promise<string> | Promise对象,返回授权令牌。 | 4127 4128**示例:** 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 4144为指定应用账号设置特定鉴权类型的授权令牌。使用callback异步回调。 4145 4146> **说明:** 4147> 4148> 从 API version 8开始支持,从API version 9开始废弃。建议使用[setAuthToken](#setauthtoken9)替代。 4149 4150**系统能力:** SystemCapability.Account.AppAccount 4151 4152**参数:** 4153 4154| 参数名 | 类型 | 必填 | 说明 | 4155| -------- | ------------------------- | ---- | -------- | 4156| name | string | 是 | 应用账号的名称。 | 4157| authType | string | 是 | 鉴权类型。 | 4158| token | string | 是 | 授权令牌。 | 4159| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为null;否则为错误对象。 | 4160 4161**示例:** 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 4175为指定应用账号设置特定鉴权类型的授权令牌。使用Promise异步回调。 4176 4177> **说明:** 4178> 4179> 从 API version 8开始支持,从API version 9开始废弃。建议使用[setAuthToken](#setauthtoken9-1)替代。 4180 4181**系统能力:** SystemCapability.Account.AppAccount 4182 4183**参数:** 4184 4185| 参数名 | 类型 | 必填 | 说明 | 4186| -------- | ------ | ---- | -------- | 4187| name | string | 是 | 应用账号的名称。 | 4188| authType | string | 是 | 鉴权类型。 | 4189| token | string | 是 | 授权令牌。 | 4190 4191**返回值:** 4192 4193| 类型 | 说明 | 4194| ------------------- | --------------------- | 4195| Promise<void> | 无返回结果的Promise对象。 | 4196 4197**示例:** 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 4213删除指定应用账号的特定鉴权类型的授权令牌。使用callback异步回调。 4214 4215> **说明:** 4216> 4217> 从 API version 8开始支持,从API version 9开始废弃。建议使用[deleteAuthToken](#deleteauthtoken9)替代。 4218 4219**系统能力:** SystemCapability.Account.AppAccount 4220 4221**参数:** 4222 4223| 参数名 | 类型 | 必填 | 说明 | 4224| -------- | ------------------------- | ---- | ------------ | 4225| name | string | 是 | 应用账号的名称。 | 4226| owner | string | 是 | 应用账号所有者的包名。 | 4227| authType | string | 是 | 鉴权类型。 | 4228| token | string | 是 | 授权令牌。 | 4229| callback | AsyncCallback<void> | 是 | 回调函数。当删除成功时,err为null;否则为错误对象。 | 4230 4231**示例:** 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 4246删除指定应用账号的特定鉴权类型的授权令牌。使用Promise异步回调。 4247 4248> **说明:** 4249> 4250> 从 API version 8开始支持,从API version 9开始废弃。建议使用[deleteAuthToken](#deleteauthtoken9-1)替代。 4251 4252**系统能力:** SystemCapability.Account.AppAccount 4253 4254**参数:** 4255 4256| 参数名 | 类型 | 必填 | 说明 | 4257| -------- | ------ | ---- | ------------ | 4258| name | string | 是 | 应用账号的名称。 | 4259| owner | string | 是 | 应用账号所有者的包名。 | 4260| authType | string | 是 | 鉴权类型。 | 4261| token | string | 是 | 授权令牌。 | 4262 4263**返回值:** 4264 4265| 类型 | 说明 | 4266| ------------------- | --------------------- | 4267| Promise<void> | 无返回结果的Promise对象。 | 4268 4269**示例:** 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 4285设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。 4286 4287> **说明:** 4288> 4289> 从 API version 8开始支持,从API version 9开始废弃。建议使用[setAuthTokenVisibility](#setauthtokenvisibility9)替代。 4290 4291**系统能力:** SystemCapability.Account.AppAccount 4292 4293**参数:** 4294 4295| 参数名 | 类型 | 必填 | 说明 | 4296| ---------- | ------------------------- | ---- | ------------------------- | 4297| name | string | 是 | 应用账号的名称。 | 4298| authType | string | 是 | 鉴权类型。 | 4299| bundleName | string | 是 | 被设置可见性的应用包名。 | 4300| isVisible | boolean | 是 | 是否可见。true表示可见,false表示不可见。 | 4301| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为null;否则为错误对象。 | 4302 4303**示例:** 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 4318设置指定账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。 4319 4320> **说明:** 4321> 4322> 从 API version 8开始支持,从API version 9开始废弃。建议使用[setAuthTokenVisibility](#setauthtokenvisibility9-1)替代。 4323 4324**系统能力:** SystemCapability.Account.AppAccount 4325 4326**参数:** 4327 4328| 参数名 | 类型 | 必填 | 说明 | 4329| ---------- | ------- | ---- | ------------ | 4330| name | string | 是 | 应用账号的名称。 | 4331| authType | string | 是 | 鉴权类型。 | 4332| bundleName | string | 是 | 被设置可见性的应用包名。 | 4333| isVisible | boolean | 是 | 是否可见。true表示可见,false表示不可见。 | 4334 4335**返回值:** 4336 4337| 类型 | 说明 | 4338| ------------------- | --------------------- | 4339| Promise<void> | 无返回结果的Promise对象。 | 4340 4341**示例:** 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 4357检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用callback异步回调。 4358 4359> **说明:** 4360> 4361> 从 API version 8开始支持,从API version 9开始废弃。建议使用[checkAuthTokenVisibility](#checkauthtokenvisibility9)替代。 4362 4363**系统能力:** SystemCapability.Account.AppAccount 4364 4365**参数:** 4366 4367| 参数名 | 类型 | 必填 | 说明 | 4368| ---------- | ---------------------------- | ---- | ----------- | 4369| name | string | 是 | 应用账号的名称。 | 4370| authType | string | 是 | 鉴权类型。 | 4371| bundleName | string | 是 | 检查可见性的应用包名。 | 4372| callback | AsyncCallback<boolean> | 是 | 回调函数。当检查成功时,err为null,data为true表示可见,data为false表示不可见;否则为错误对象。 | 4373 4374**示例:** 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 4390检查指定应用账号的特定鉴权类型的授权令牌对指定应用的可见性。使用Promise异步回调。 4391 4392> **说明:** 4393> 4394> 从 API version 8开始支持,从API version 9开始废弃。建议使用[checkAuthTokenVisibility](#checkauthtokenvisibility9-1)替代。 4395 4396**系统能力:** SystemCapability.Account.AppAccount 4397 4398**参数:** 4399 4400| 参数名 | 类型 | 必填 | 说明 | 4401| ---------- | ------ | ---- | ------------- | 4402| name | string | 是 | 应用账号的名称。 | 4403| authType | string | 是 | 鉴权类型。 | 4404| bundleName | string | 是 | 用于检查可见性的应用包名。 | 4405 4406**返回值:** 4407 4408| 类型 | 说明 | 4409| ---------------------- | --------------------- | 4410| Promise<boolean> | Promise对象。返回true表示指定鉴权类型的OAuth令牌对特定应用的可见,返回false表示不可见。 | 4411 4412**示例:** 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 4429获取指定账号对调用方可见的所有授权令牌。使用callback异步回调。 4430 4431> **说明:** 4432> 4433> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAllAuthTokens](#getallauthtokens9)替代。 4434 4435**系统能力:** SystemCapability.Account.AppAccount 4436 4437**参数:** 4438 4439| 参数名 | 类型 | 必填 | 说明 | 4440| -------- | ---------------------------------------- | ---- | ----------- | 4441| name | string | 是 | 应用账号的名称。 | 4442| owner | string | 是 | 应用账号所有者的包名。 | 4443| callback | AsyncCallback<Array<[OAuthTokenInfo](#oauthtokeninfodeprecated)>> | 是 | 回调函数。当获取成功时,err为null,data为授权令牌数组;否则为错误对象。 | 4444 4445**示例:** 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 4461获取指定账号对调用方可见的所有授权令牌。使用Promise异步回调。 4462 4463> **说明:** 4464> 4465> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAllAuthTokens](#getallauthtokens9-1)替代。 4466 4467**系统能力:** SystemCapability.Account.AppAccount 4468 4469**参数:** 4470 4471| 参数名 | 类型 | 必填 | 说明 | 4472| ----- | ------ | ---- | ----------- | 4473| name | string | 是 | 应用账号的名称。 | 4474| owner | string | 是 | 应用账号所有者的包名。 | 4475 4476**返回值:** 4477 4478| 类型 | 说明 | 4479| ---------------------------------------- | --------------------- | 4480| Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Promise对象,返回授权令牌数组。 | 4481 4482**示例:** 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 4499获取指定应用账号的特定鉴权类型的授权列表,即被授权的包名数组(令牌的授权列表通过setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated)来设置)。使用callback异步回调。 4500 4501> **说明:** 4502> 4503> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthList](#getauthlist9)替代。 4504 4505**系统能力:** SystemCapability.Account.AppAccount 4506 4507**参数:** 4508 4509| 参数名 | 类型 | 必填 | 说明 | 4510| -------- | ---------------------------------------- | ---- | ----------------------- | 4511| name | string | 是 | 应用账号的名称。 | 4512| authType | string | 是 | 鉴权类型。 | 4513| callback | AsyncCallback<Array<string>> | 是 | 回调函数。当获取成功时,err为null,data为被授权的包名数组;否则为错误对象。 | 4514 4515**示例:** 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 4530获取指定应用账号的特定鉴权类型的授权列表,即被授权的包名数组(令牌的授权列表通过setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated)来设置)。使用Promise异步回调。 4531 4532> **说明:** 4533> 4534> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthList](#getauthlist9-1)替代。 4535 4536**系统能力:** SystemCapability.Account.AppAccount 4537 4538**参数:** 4539 4540| 参数名 | 类型 | 必填 | 说明 | 4541| -------- | ------ | ---- | ----------------------- | 4542| name | string | 是 | 应用账号的名称。 | 4543| authType | string | 是 | 鉴权类型。 | 4544 4545**返回值:** 4546 4547| 类型 | 说明 | 4548| ---------------------------------- | --------------------- | 4549| Promise<Array<string>> | Promise对象,返回被授权的包名数组。 | 4550 4551**示例:** 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 4567获取鉴权会话的认证器回调。使用callback异步回调。 4568 4569> **说明:** 4570> 4571> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthCallback](#getauthcallback9)替代。 4572 4573**系统能力:** SystemCapability.Account.AppAccount 4574 4575**参数:** 4576 4577| 参数名 | 类型 | 必填 | 说明 | 4578| --------- | ---------------------------------------- | ---- | -------- | 4579| sessionId | string | 是 | 鉴权会话的标识。 | 4580| callback | AsyncCallback<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | 是 | 回调函数。当获取鉴权会话的认证器回调函数成功时,err为null,data为认证器回调函数;否则为错误对象。 | 4581 4582**示例:** 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 生命周期函数 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 4612获取鉴权会话的认证器回调。使用Promise异步回调。 4613 4614> **说明:** 4615> 4616> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getAuthCallback](#getauthcallback9-1)替代。 4617 4618**系统能力:** SystemCapability.Account.AppAccount 4619 4620**参数:** 4621 4622| 参数名 | 类型 | 必填 | 说明 | 4623| --------- | ------ | ---- | -------- | 4624| sessionId | string | 是 | 鉴权会话的标识。 | 4625 4626**返回值:** 4627 4628| 类型 | 说明 | 4629| ------------------------------------ | --------------------- | 4630| Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Promise对象,返回鉴权会话的认证器回调对象。 | 4631 4632**示例:** 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 生命周期函数 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 4660获取指定应用的认证器信息。使用callback异步回调。 4661 4662> **说明:** 4663> 4664> 从 API version 8开始支持,从API version 9开始废弃。建议使用[queryAuthenticatorInfo](#queryauthenticatorinfo9)替代。 4665 4666**系统能力:** SystemCapability.Account.AppAccount 4667 4668**参数:** 4669 4670| 参数名 | 类型 | 必填 | 说明 | 4671| -------- | -------------------------------------- | ---- | ----------- | 4672| owner | string | 是 | 应用账号所有者的包名。 | 4673| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | 是 | 回调函数。当获取成功时,err为null,data为认证器信息对象;否则为错误对象。 | 4674 4675**示例:** 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 4691获取指定应用的认证器信息。使用Promise异步回调。 4692 4693> **说明:** 4694> 4695> 从 API version 8开始支持,从API version 9开始废弃。建议使用[queryAuthenticatorInfo](#queryauthenticatorinfo9-1)替代。 4696 4697**系统能力:** SystemCapability.Account.AppAccount 4698 4699**参数:** 4700 4701| 参数名 | 类型 | 必填 | 说明 | 4702| ----- | ------ | ---- | ----------- | 4703| owner | string | 是 | 应用账号所有者的包名。 | 4704 4705**返回值:** 4706 4707| 类型 | 说明 | 4708| -------------------------------- | --------------------- | 4709| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise对象,返回指定应用的认证器信息对象。 | 4710 4711**示例:** 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 4726表示应用账号信息。 4727 4728**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4729 4730| 名称 | 类型 | 必填 | 说明 | 4731| ----- | ------ | ---- | ----------- | 4732| owner | string | 是 | 应用账号所有者的包名。 | 4733| name | string | 是 | 应用账号的名称。 | 4734 4735## AuthTokenInfo<sup>9+</sup> 4736 4737表示Auth令牌信息。 4738 4739**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4740 4741| 名称 | 类型 | 必填 | 说明 | 4742| -------------------- | -------------- | ----- | ---------------- | 4743| authType<sup>9+</sup> | string | 是 | 令牌的鉴权类型。 | 4744| token<sup>9+</sup> | string | 是 | 令牌的取值。 | 4745| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | 否 | 令牌所属的账号信息,默认为空。| 4746 4747## OAuthTokenInfo<sup>(deprecated)</sup> 4748 4749表示OAuth令牌信息。 4750 4751> **说明:** 4752> 4753> 从 API version 8开始支持,从API version 9开始废弃。建议使用[AuthTokenInfo](#authtokeninfo9)替代。 4754 4755**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4756 4757| 名称 | 类型 | 必填 | 说明 | 4758| -------------------- | -------------- | ----- | ---------------- | 4759| authType | string | 是 | 令牌的鉴权类型。 | 4760| token | string | 是 | 令牌的取值。 | 4761 4762## AuthenticatorInfo<sup>8+</sup> 4763 4764表示OAuth认证器信息。 4765 4766**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4767 4768| 名称 | 类型 | 必填 | 说明 | 4769| ------- | ------ | ---- | ---------- | 4770| owner | string | 是 | 认证器的所有者的包名。 | 4771| iconId | number | 是 | 认证器的图标标识。 | 4772| labelId | number | 是 | 认证器的标签标识。 | 4773 4774## AuthResult<sup>9+</sup> 4775 4776表示认证结果信息。 4777 4778**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4779 4780| 名称 | 类型 | 必填 | 说明 | 4781| ------- | ------ | ---- | ---------- | 4782| account | [AppAccountInfo](#appaccountinfo) | 否 | 令牌所属的账号信息,默认为空。 | 4783| tokenInfo | [AuthTokenInfo](#authtokeninfo9) | 否 | 令牌信息,默认为空。 | 4784 4785## CreateAccountOptions<sup>9+</sup> 4786 4787表示创建账号的选项。 4788 4789**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4790 4791| 名称 | 类型 | 必填 | 说明 | 4792| ------- | ------ | ---- | ---------- | 4793| customData | Record<string, string> | 否 | 自定义数据,默认为空。 | 4794 4795## CreateAccountImplicitlyOptions<sup>9+</sup> 4796 4797表示隐式创建账号的选项。 4798 4799**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4800 4801| 名称 | 类型 | 必填 | 说明 | 4802| ------- | ------ | ---- | ---------- | 4803| requiredLabels | Array<string> | 否 | 所需的标签,默认为空。 | 4804| authType | string | 否 | 鉴权类型,默认为空。 | 4805| parameters | Record<string, Object> | 否 | 自定义参数对象,默认为空。 | 4806## SelectAccountsOptions<sup>9+</sup> 4807 4808表示用于选择账号的选项。 4809 4810**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4811 4812| 名称 | 类型 | 必填 | 说明 | 4813| --------------- | --------------------------- | ----- | ------------------- | 4814| allowedAccounts | Array<[AppAccountInfo](#appaccountinfo)> | 否 | 允许的账号数组,默认为空。 | 4815| allowedOwners | Array<string> | 否 | 允许的账号所有者数组,默认为空。 | 4816| requiredLabels | Array<string> | 否 | 认证器的标签标识,默认为空。 | 4817 4818## VerifyCredentialOptions<sup>9+</sup> 4819 4820表示用于验证凭据的选项。 4821 4822**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4823 4824| 名称 | 类型 | 必填 | 说明 | 4825| -------------- | ---------------------- | ----- | -------------- | 4826| credentialType | string | 否 | 凭据类型,默认为空。 | 4827| credential | string | 否 | 凭据取值,默认为空。 | 4828| parameters | Record<string, Object> | 否 | 自定义参数对象,默认为空。 | 4829 4830 4831## SetPropertiesOptions<sup>9+</sup> 4832 4833表示用于设置属性的选项。 4834 4835**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4836 4837| 名称 | 类型 | 必填 | 说明 | 4838| ---------- | ---------------------- | ----- | -------------- | 4839| properties | Record<string, Object> | 否 | 属性对象,默认为空。 | 4840| parameters | Record<string, Object> | 否 | 自定义参数对象,默认为空。 | 4841 4842## Constants<sup>8+</sup> 4843 4844表示常量的枚举。 4845 4846**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4847 4848| 名称 | 值 | 说明 | 4849| -------------------------------- | ---------------------- | ----------------------- | 4850| ACTION_ADD_ACCOUNT_IMPLICITLY<sup>(deprecated)</sup> | 'addAccountImplicitly' | 表示操作,隐式添加账号。 | 4851| ACTION_AUTHENTICATE<sup>(deprecated)</sup> | 'authenticate' | 表示操作,鉴权。 | 4852| ACTION_CREATE_ACCOUNT_IMPLICITLY<sup>9+</sup> | 'createAccountImplicitly' | 表示操作,隐式创建账号。 | 4853| ACTION_AUTH<sup>9+</sup> | 'auth' | 表示操作,鉴权。 | 4854| ACTION_VERIFY_CREDENTIAL<sup>9+</sup> | 'verifyCredential' | 表示操作,验证凭据。 | 4855| ACTION_SET_AUTHENTICATOR_PROPERTIES<sup>9+</sup> | 'setAuthenticatorProperties' | 表示操作,设置认证器属性。 | 4856| KEY_NAME | 'name' | 表示键名,应用账号的名称。 | 4857| KEY_OWNER | 'owner' | 表示键名,应用账号所有者的包名。| 4858| KEY_TOKEN | 'token' | 表示键名,令牌。 | 4859| KEY_ACTION | 'action' | 表示键名,操作。 | 4860| KEY_AUTH_TYPE | 'authType' | 表示键名,鉴权类型。 | 4861| KEY_SESSION_ID | 'sessionId' | 表示键名,会话标识。 | 4862| KEY_CALLER_PID | 'callerPid' | 表示键名,调用方PID。 | 4863| KEY_CALLER_UID | 'callerUid' | 表示键名,调用方UID。 | 4864| KEY_CALLER_BUNDLE_NAME | 'callerBundleName' | 表示键名,调用方包名。 | 4865| KEY_REQUIRED_LABELS<sup>9+</sup> | 'requiredLabels' | 表示键名,必需的标签。 | 4866| KEY_BOOLEAN_RESULT<sup>9+</sup> | 'booleanResult' | 表示键名,布尔返回值。 | 4867 4868## ResultCode<sup>(deprecated)</sup> 4869 4870表示返回码的枚举。 4871 4872> **说明:**<br/> 4873> 从API version 8开始支持,从API version 9开始废弃。相关信息建议查看[错误码文档](errorcode-account.md)替代。 4874 4875**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 4876 4877| 名称 | 值 | 说明 | 4878| ----------------------------------- | ----- | ------------ | 4879| SUCCESS | 0 | 表示操作成功。 | 4880| ERROR_ACCOUNT_NOT_EXIST | 10001 | 表示应用账号不存在。 | 4881| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | 表示应用账号服务异常。 | 4882| ERROR_INVALID_PASSWORD | 10003 | 表示密码无效。 | 4883| ERROR_INVALID_REQUEST | 10004 | 表示请求无效。 | 4884| ERROR_INVALID_RESPONSE | 10005 | 表示响应无效。 | 4885| ERROR_NETWORK_EXCEPTION | 10006 | 表示网络异常。 | 4886| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | 表示认证器不存在。 | 4887| ERROR_OAUTH_CANCELED | 10008 | 表示鉴权取消。 | 4888| ERROR_OAUTH_LIST_TOO_LARGE | 10009 | 表示开放授权列表过大。 | 4889| ERROR_OAUTH_SERVICE_BUSY | 10010 | 表示开放授权服务忙碌。 | 4890| ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | 表示开放授权服务异常。 | 4891| ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | 表示鉴权会话不存在。 | 4892| ERROR_OAUTH_TIMEOUT | 10013 | 表示鉴权超时。 | 4893| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | 表示开放授权令牌不存在。 | 4894| ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | 表示开放授权令牌过多。 | 4895| ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | 表示不支持的鉴权操作。 | 4896| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | 表示不支持的鉴权类型。 | 4897| ERROR_PERMISSION_DENIED | 10018 | 表示权限不足。 | 4898 4899## AuthCallback<sup>9+</sup> 4900 4901认证器回调类。 4902 4903### onResult<sup>9+</sup> 4904 4905onResult: (code: number, result?: AuthResult) => void 4906 4907通知请求结果。 4908 4909**系统能力:** SystemCapability.Account.AppAccount 4910 4911**参数:** 4912 4913| 参数名 | 类型 | 必填 | 说明 | 4914| ------ | -------------------- | ---- | ------ | 4915| code | number | 是 | 鉴权结果码。 | 4916| result | [AuthResult](#authresult9) | 否 | 鉴权结果,默认为空,表示不接收认证结果信息。 | 4917 4918**示例:** 4919 4920 ```ts 4921 import { BusinessError } from '@kit.BasicServicesKit'; 4922 4923 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 4924 let sessionId = '1234'; 4925 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 4926 let result: appAccount.AuthResult = { 4927 account: { 4928 name: 'Lisi', 4929 owner: 'com.example.accountjsdemo', 4930 }, 4931 tokenInfo: { 4932 token: 'xxxxxx', 4933 authType: 'getSocialData' 4934 } 4935 }; 4936 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4937 }).catch((err: BusinessError) => { 4938 console.log('getAuthCallback err: ' + JSON.stringify(err)); 4939 }); 4940 ``` 4941 4942### onRequestRedirected<sup>9+</sup> 4943 4944onRequestRedirected: (request: Want) => void 4945 4946通知请求被跳转。 4947 4948**系统能力:** SystemCapability.Account.AppAccount 4949 4950**参数:** 4951 4952| 参数名 | 类型 | 必填 | 说明 | 4953| ------- | ---- | ---- | ---------- | 4954| request | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 用于跳转的请求信息。 | 4955 4956**示例:** 4957 4958 ```ts 4959 import { Want } from '@kit.AbilityKit'; 4960 4961 class MyAuthenticator extends appAccount.Authenticator { 4962 createAccountImplicitly( 4963 options: appAccount.CreateAccountImplicitlyOptions, callback: appAccount.AuthCallback) { 4964 let want: Want = { 4965 bundleName: 'com.example.accountjsdemo', 4966 abilityName: 'com.example.accountjsdemo.LoginAbility', 4967 }; 4968 callback.onRequestRedirected(want); 4969 } 4970 4971 auth(name: string, authType: string, 4972 options: Record<string, Object>, callback: appAccount.AuthCallback) { 4973 let result: appAccount.AuthResult = { 4974 account: { 4975 name: 'Lisi', 4976 owner: 'com.example.accountjsdemo', 4977 }, 4978 tokenInfo: { 4979 token: 'xxxxxx', 4980 authType: 'getSocialData' 4981 } 4982 }; 4983 callback.onResult(appAccount.ResultCode.SUCCESS, result); 4984 } 4985 } 4986 ``` 4987 4988### onRequestContinued<sup>9+</sup> 4989 4990onRequestContinued?: () => void 4991 4992通知请求被继续处理。 4993 4994**系统能力:** SystemCapability.Account.AppAccount 4995 4996**示例:** 4997 4998 ```ts 4999 import { BusinessError } from '@kit.BasicServicesKit'; 5000 5001 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 5002 let sessionId = '1234'; 5003 appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => { 5004 if (callback.onRequestContinued != undefined) { 5005 callback.onRequestContinued(); 5006 } 5007 }).catch((err: BusinessError) => { 5008 console.log('getAuthCallback err: ' + JSON.stringify(err)); 5009 }); 5010 ``` 5011 5012## AuthenticatorCallback<sup>(deprecated)</sup> 5013 5014OAuth认证器回调接口。 5015 5016> **说明:** 5017> 5018> 从 API version 8开始支持,从API version 9开始废弃。建议使用[AuthCallback](#authcallback9)替代。 5019 5020### onResult<sup>8+</sup> 5021 5022onResult: (code: number, result: {[key: string]: any;}) => void 5023 5024通知请求结果。 5025 5026**系统能力:** SystemCapability.Account.AppAccount 5027 5028**参数:** 5029 5030| 参数名 | 类型 | 必填 | 说明 | 5031| ------ | -------------------- | ---- | ------ | 5032| code | number | 是 | 鉴权结果码。 | 5033| result | {[key: string]: any} | 是 | 鉴权结果。 | 5034 5035**示例:** 5036 5037 ```ts 5038 import { BusinessError } from '@kit.BasicServicesKit'; 5039 5040 let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager(); 5041 let sessionId = '1234'; 5042 appAccountManager.getAuthenticatorCallback(sessionId).then((callback: appAccount.AuthenticatorCallback) => { 5043 callback.onResult(appAccount.ResultCode.SUCCESS, { 5044 name: 'LiSi', 5045 owner: 'com.example.accountjsdemo', 5046 authType: 'getSocialData', 5047 token: 'xxxxxx'} 5048 ); 5049 }).catch((err: BusinessError) => { 5050 console.log('getAuthenticatorCallback err: ' + JSON.stringify(err)); 5051 }); 5052 ``` 5053 5054### onRequestRedirected<sup>8+</sup> 5055 5056onRequestRedirected: (request: Want) => void 5057 5058通知请求被跳转。 5059 5060**系统能力:** SystemCapability.Account.AppAccount 5061 5062**参数:** 5063 5064| 参数名 | 类型 | 必填 | 说明 | 5065| ------- | ---- | ---- | ---------- | 5066| request | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 用于跳转的请求信息。 | 5067 5068**示例:** 5069 5070 ```ts 5071 import { Want } from '@kit.AbilityKit'; 5072 5073 class MyAuthenticator extends appAccount.Authenticator { 5074 addAccountImplicitly(authType: string, callerBundleName: string, 5075 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5076 let want: Want = { 5077 bundleName: 'com.example.accountjsdemo', 5078 abilityName: 'com.example.accountjsdemo.LoginAbility', 5079 }; 5080 callback.onRequestRedirected(want); 5081 } 5082 5083 authenticate(name: string, authType: string, callerBundleName: string, 5084 options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) { 5085 callback.onResult(appAccount.ResultCode.SUCCESS, { 5086 name: name, 5087 authType: authType, 5088 token: 'xxxxxx'} 5089 ); 5090 } 5091 } 5092 ``` 5093 5094## Authenticator<sup>8+</sup> 5095 5096认证器基类。 5097 5098### createAccountImplicitly<sup>9+</sup> 5099 5100createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 5101 5102根据指定的账号所有者隐式地创建应用账号,并使用callback异步回调返回结果。 5103 5104**系统能力:** SystemCapability.Account.AppAccount 5105 5106**参数:** 5107 5108| 参数名 | 类型 | 必填 | 说明 | 5109| ---------------- | --------------------- | ---- | --------------- | 5110| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | 是 | 隐式创建账号的选项。 | 5111| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调对象,用于返回创建结果。 | 5112 5113### addAccountImplicitly<sup>(deprecated)</sup> 5114 5115addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5116 5117根据指定的鉴权类型和可选项,隐式地添加应用账号,并使用callback异步回调返回结果。 5118 5119> **说明:** 5120> 5121> 从 API version 8开始支持, 从API version 9开始废弃。建议使用[createAccountImplicitly](#createaccountimplicitly9-2)替代。 5122 5123**系统能力:** SystemCapability.Account.AppAccount 5124 5125**参数:** 5126 5127| 参数名 | 类型 | 必填 | 说明 | 5128| ---------------- | --------------------- | ---- | --------------- | 5129| authType | string | 是 | 应用账号的鉴权类型。 | 5130| callerBundleName | string | 是 | 鉴权请求方的包名。 | 5131| options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | 5132| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | 是 | 认证器回调,用于返回鉴权结果。 | 5133 5134### auth<sup>9+</sup> 5135 5136auth(name: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void 5137 5138对应用账号进行鉴权以获取授权令牌,并使用callback异步回调返回结果。 5139 5140**系统能力:** SystemCapability.Account.AppAccount 5141 5142**参数:** 5143 5144| 参数名 | 类型 | 必填 | 说明 | 5145| ---------------- | --------------------- | ---- | --------------- | 5146| name | string | 是 | 应用账号的名称。 | 5147| authType | string | 是 | 应用账号的鉴权类型。 | 5148| options | Record<string, Object> | 是 | 鉴权所需要的可选项。 | 5149| callback | [AuthCallback](#authcallback9) | 是 | 回调对象,用于返回鉴权结果。 | 5150 5151### authenticate<sup>(deprecated)</sup> 5152 5153authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void 5154 5155对应用账号进行鉴权,获取OAuth令牌,并使用callback异步回调返回结果。 5156 5157> **说明:** 5158> 5159> 从 API version 8开始支持, 从API version 9开始废弃。建议使用[auth](#auth9-2)替代。 5160 5161**系统能力:** SystemCapability.Account.AppAccount 5162 5163**参数:** 5164 5165| 参数名 | 类型 | 必填 | 说明 | 5166| ---------------- | --------------------- | ---- | --------------- | 5167| name | string | 是 | 应用账号的名称。 | 5168| authType | string | 是 | 应用账号的鉴权类型。 | 5169| callerBundleName | string | 是 | 鉴权请求方的包名。 | 5170| options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | 5171| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | 是 | 认证器回调,用于返回鉴权结果。 | 5172 5173### verifyCredential<sup>9+</sup> 5174 5175verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void 5176 5177验证应用账号的凭据,并使用callback异步回调返回结果。 5178 5179**系统能力:** SystemCapability.Account.AppAccount 5180 5181**参数:** 5182 5183| 参数名 | 类型 | 必填 | 说明 | 5184| ---------------- | --------------------- | ---- | --------------- | 5185| name | string | 是 | 应用账号的名称。 | 5186| options | [VerifyCredentialOptions](#verifycredentialoptions9) | 是 | 验证凭据的可选项。 | 5187| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调,用于返回验证结果。 | 5188 5189### setProperties<sup>9+</sup> 5190 5191setProperties(options: SetPropertiesOptions, callback: AuthCallback): void 5192 5193设置认证器属性,并使用callback异步回调返回结果。 5194 5195**系统能力:** SystemCapability.Account.AppAccount 5196 5197**参数:** 5198 5199| 参数名 | 类型 | 必填 | 说明 | 5200| ---------------- | --------------------- | ---- | --------------- | 5201| options | [SetPropertiesOptions](#setpropertiesoptions9) | 是 | 设置属性的可选项。 | 5202| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调,用于返回设置结果。 | 5203 5204### checkAccountLabels<sup>9+</sup> 5205 5206checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void 5207 5208检查账号标签,并使用callback异步回调返回结果。 5209 5210**系统能力:** SystemCapability.Account.AppAccount 5211 5212**参数:** 5213 5214| 参数名 | 类型 | 必填 | 说明 | 5215| ---------------- | --------------------- | ---- | --------------- | 5216| name | string | 是 | 应用账号的名称。 | 5217| labels | Array<string> | 是 | 标签数组。 | 5218| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调,用于返回检查结果。 | 5219 5220### checkAccountRemovable<sup>9+</sup> 5221 5222checkAccountRemovable(name: string, callback: AuthCallback): void 5223 5224判断账号是否可以删除,并使用callback异步回调返回结果。 5225 5226**系统能力:** SystemCapability.Account.AppAccount 5227 5228**参数:** 5229 5230| 参数名 | 类型 | 必填 | 说明 | 5231| ---------------- | --------------------- | ---- | --------------- | 5232| name | string | 是 | 应用账号的名称。 | 5233| callback | [AuthCallback](#authcallback9) | 是 | 认证器回调,用于返回判断结果。 | 5234 5235### getRemoteObject<sup>9+</sup> 5236 5237getRemoteObject(): rpc.RemoteObject; 5238 5239获取认证器的远程对象,不可以重载实现。 5240 5241**系统能力:** SystemCapability.Account.AppAccount 5242 5243**示例:** 5244 5245 <!--code_no_check--> 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 生命周期函数, 需要放在serviceAbility中 5285 let authenticator = new MyAuthenticator(); 5286 return authenticator.getRemoteObject(); 5287 } 5288 } 5289 ``` 5290