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