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