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