• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 应用帐号管理
2
3> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
4> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
5
6
7## 导入模块
8
9```js
10import account_appAccount from '@ohos.account.appAccount';
11```
12
13
14## account_appAccount.createAppAccountManager
15
16createAppAccountManager(): AppAccountManager
17
18获取应用帐号模块对象。
19
20**系统能力:** SystemCapability.Account.AppAccount
21
22**返回值:**
23| 类型                | 说明           |
24| ----------------- | ------------ |
25| AppAccountManager | 获取应用帐号模块的实例。 |
26
27**示例:**
28  ```js
29  const appAccountManager = account_appAccount.createAppAccountManager();
30  ```
31
32## AppAccountManager
33
34管理应用帐号模块的实例。
35
36### addAccount
37
38addAccount(name: string, callback: AsyncCallback<void>): void
39
40将此应用的帐号名添加到帐号管理服务中,使用callback回调异步返回结果。
41
42**系统能力:** SystemCapability.Account.AppAccount
43
44**参数:**
45
46| 参数名      | 类型                        | 必填   | 说明                    |
47| -------- | ------------------------- | ---- | --------------------- |
48| name     | string                    | 是    | 要添加的应用帐户的名称。          |
49| callback | AsyncCallback<void> | 是    | 将此应用的帐号名添加到帐号管理服务的回调。 |
50
51**示例:**
52
53  ```js
54  const appAccountManager = account_appAccount.createAppAccountManager();
55  appAccountManager.addAccount("WangWu", (err) => {
56      console.log("addAccount err: " + JSON.stringify(err));
57  });
58  ```
59
60### addAccount
61
62addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void
63
64将此应用程序的帐号名和额外信息添加到帐号管理服务中,使用callback回调异步返回结果。
65
66**系统能力:** SystemCapability.Account.AppAccount
67
68**参数:**
69
70| 参数名       | 类型                        | 必填   | 说明                                       |
71| --------- | ------------------------- | ---- | ---------------------------------------- |
72| name      | string                    | 是    | 要添加的应用帐户的名称。                             |
73| extraInfo | string                    | 是    | 要添加的应用帐户的额外信息(例如token等),额外的信息不能是应用帐号的敏感信息。 |
74| callback  | AsyncCallback<void> | 是    | 将此应用程序的帐号名和额外信息添加到帐号管理服务中的回调。            |
75
76**示例:**
77
78  ```js
79  const appAccountManager = account_appAccount.createAppAccountManager();
80  appAccountManager.addAccount("LiSi", "token101", (err) => {
81      console.log("addAccount err: " + JSON.stringify(err));
82  });
83  ```
84
85
86
87### addAccount
88
89addAccount(name: string, extraInfo?: string): Promise<void>
90
91将此应用的帐号名或额外信息添加到帐号管理服务中,使用Promise方式异步返回结果。
92
93**系统能力:** SystemCapability.Account.AppAccount
94
95**参数:**
96
97| 参数名       | 类型     | 必填   | 说明                               |
98| --------- | ------ | ---- | -------------------------------- |
99| name      | string | 是    | 要添加的应用帐户的名称。                     |
100| extraInfo | string | 是    | 要添加的应用帐户的额外信息,额外的信息不能是应用帐号的敏感信息。 |
101
102**返回值:**
103
104| 类型                  | 说明                    |
105| ------------------- | --------------------- |
106| Promise<void> | Promise实例,用于获取异步返回结果。 |
107
108**示例:**
109
110  ```js
111  const appAccountManager = account_appAccount.createAppAccountManager();
112  appAccountManager.addAccount("LiSi", "token101").then(()=> {
113      console.log('addAccount Success');
114  }).catch((err) => {
115      console.log("addAccount err: "  + JSON.stringify(err));
116  });
117  ```
118
119### addAccountImplicitly<sup>8+</sup>
120
121addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
122
123根据指定的帐号所有者、鉴权类型和可选项,隐式地添加应用帐号,并使用callback回调异步返回结果。
124
125**系统能力:** SystemCapability.Account.AppAccount
126
127**参数:**
128
129| 参数名      | 类型                    | 必填   | 说明              |
130| -------- | --------------------- | ---- | --------------- |
131| owner    | string                | 是    | 要添加的应用帐户的所有者包名。 |
132| authType | string                | 是    | 要添加的应用帐户的鉴权类型。  |
133| options  | {[key: string]: any}  | 是    | 鉴权所需要的可选项。      |
134| callback | AuthenticatorCallback | 是    | 认证器回调,用于返回鉴权结果。 |
135
136**示例:**
137
138  ```js
139  import featureAbility from '@ohos.ability.featureAbility';
140
141  function onResultCallback(code, result) {
142      console.log("resultCode: "  + code);
143      console.log("result: "  + JSON.stringify(result));
144  }
145
146  function onRequestRedirectedCallback(request) {
147      let abilityStartSetting = {want: request};
148      featureAbility.startAbility(abilityStartSetting, (err)=>{
149          console.log("startAbility err: " + JSON.stringify(err));
150      });
151  }
152
153  const appAccountManager = account_appAccount.createAppAccountManager();
154  appAccountManager.addAccountImplicitly("com.example.ohos.accountjsdemo", "getSocialData", {}, {
155      onResult: onResultCallback,
156      onRequestRedirected: onRequestRedirectedCallback
157  });
158  ```
159
160### deleteAccount
161
162deleteAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
163
164从帐号管理服务中删除应用帐号,使用callback回调异步返回结果。
165
166**系统能力:** SystemCapability.Account.AppAccount
167
168**参数:**
169
170| 参数名      | 类型                        | 必填   | 说明                |
171| -------- | ------------------------- | ---- | ----------------- |
172| name     | string                    | 是    | 要删除的应用帐户的名称。      |
173| callback | AsyncCallback&lt;void&gt; | 是    | 帐号管理服务中删除应用帐号的回调。 |
174
175**示例:**
176
177  ```js
178  const appAccountManager = account_appAccount.createAppAccountManager();
179  appAccountManager.deleteAccount("ZhaoLiu", (err) => {
180      console.log("deleteAccount err: " + JSON.stringify(err));
181   });
182  ```
183
184### deleteAccount
185
186deleteAccount(name: string): Promise&lt;void&gt;
187
188从帐号管理服务中删除应用帐号,使用Promise方式异步返回结果。
189
190**系统能力:** SystemCapability.Account.AppAccount
191
192**参数:**
193
194| 参数名  | 类型     | 必填   | 说明           |
195| ---- | ------ | ---- | ------------ |
196| name | string | 是    | 要删除的应用帐户的名称。 |
197
198**返回值:**
199
200| 类型                  | 说明                    |
201| :------------------ | :-------------------- |
202| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
203
204**示例:**
205
206  ```js
207  const appAccountManager = account_appAccount.createAppAccountManager();
208  appAccountManager.deleteAccount("ZhaoLiu").then(() => {
209        console.log('deleteAccount Success');
210   }).catch((err) => {
211      console.log("deleteAccount err: "  + JSON.stringify(err));
212  });
213  ```
214
215### disableAppAccess
216
217disableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
218
219禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。
220
221**系统能力:** SystemCapability.Account.AppAccount
222
223**参数:**
224
225| 参数名        | 类型                        | 必填   | 说明                              |
226| ---------- | ------------------------- | ---- | ------------------------------- |
227| name       | string                    | 是    | 要禁用访问的第三方应用帐户的名称。               |
228| bundleName | string                    | 是    | 第三方应用的包名。                       |
229| callback   | AsyncCallback&lt;void&gt; | 是    | 禁止指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 |
230
231**示例:**
232
233  ```js
234  const appAccountManager = account_appAccount.createAppAccountManager();
235  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => {
236      console.log("disableAppAccess err: " + JSON.stringify(err));
237  });
238  ```
239
240### disableAppAccess
241
242disableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
243
244禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。
245
246**系统能力:** SystemCapability.Account.AppAccount
247
248**参数:**
249
250| 参数名        | 类型     | 必填   | 说明                |
251| ---------- | ------ | ---- | ----------------- |
252| name       | string | 是    | 要禁用访问的第三方应用帐户的名称。 |
253| bundleName | string | 是    | 第三方应用的包名。         |
254
255**返回值:**
256
257| 类型                  | 说明                    |
258| :------------------ | :-------------------- |
259| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
260
261**示例:**
262
263  ```js
264  const appAccountManager = account_appAccount.createAppAccountManager();
265  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => {
266      console.log('disableAppAccess Success');
267  }).catch((err) => {
268      console.log("disableAppAccess err: "  + JSON.stringify(err));
269  });
270  ```
271
272### enableAppAccess
273
274enableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
275
276允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。
277
278**系统能力:** SystemCapability.Account.AppAccount
279
280**参数:**
281
282| 参数名        | 类型                        | 必填   | 说明                              |
283| ---------- | ------------------------- | ---- | ------------------------------- |
284| name       | string                    | 是    | 应用帐号名称。                         |
285| bundleName | string                    | 是    | 第三方应用的包名。                       |
286| callback   | AsyncCallback&lt;void&gt; | 是    | 允许指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 |
287
288**示例:**
289
290  ```js
291  const appAccountManager = account_appAccount.createAppAccountManager();
292  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => {
293      console.log("enableAppAccess: " + JSON.stringify(err));
294   });
295  ```
296
297### enableAppAccess
298
299enableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
300
301允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。
302
303**系统能力:** SystemCapability.Account.AppAccount
304
305**参数:**
306
307| 参数名        | 类型     | 必填   | 说明        |
308| ---------- | ------ | ---- | --------- |
309| name       | string | 是    | 应用帐号名称。   |
310| bundleName | string | 是    | 第三方应用的包名。 |
311
312**返回值:**
313
314| 类型                  | 说明                    |
315| :------------------ | :-------------------- |
316| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
317
318**示例:**
319
320  ```js
321  const appAccountManager = account_appAccount.createAppAccountManager();
322  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => {
323       console.log('enableAppAccess Success');
324  }).catch((err) => {
325      console.log("enableAppAccess err: "  + JSON.stringify(err));
326  });
327  ```
328
329### checkAppAccountSyncEnable
330
331checkAppAccountSyncEnable(name: string, callback: AsyncCallback&lt;boolean&gt;): void
332
333检查指定应用帐号是否允许应用数据同步,使用callback回调异步返回结果。
334
335**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
336
337**系统能力:** SystemCapability.Account.AppAccount
338
339**参数:**
340
341| 参数名      | 类型                           | 必填   | 说明                     |
342| -------- | ---------------------------- | ---- | ---------------------- |
343| name     | string                       | 是    | 应用帐号名称。                |
344| callback | AsyncCallback&lt;boolean&gt; | 是    | 检查指定应用帐号是否允许应用数据同步的回调。 |
345
346**示例:**
347
348  ```js
349  const appAccountManager = account_appAccount.createAppAccountManager();
350  appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => {
351      console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
352      console.log('checkAppAccountSyncEnable result: ' + result);
353  });
354  ```
355
356### checkAppAccountSyncEnable
357
358checkAppAccountSyncEnable(name: string): Promise&lt;boolean&gt;
359
360检查指定应用帐号是否允许应用数据同步,使用Promise方式异步返回结果。
361
362**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
363
364**系统能力:** SystemCapability.Account.AppAccount
365
366**参数:**
367
368| 参数名  | 类型     | 必填   | 说明      |
369| ---- | ------ | ---- | ------- |
370| name | string | 是    | 应用帐号名称。 |
371
372**返回值:**
373
374| 类型                     | 说明                    |
375| :--------------------- | :-------------------- |
376| Promise&lt;boolean&gt; | Promise实例,用于获取异步返回结果。 |
377
378**示例:**
379
380  ```js
381  const appAccountManager = account_appAccount.createAppAccountManager();
382  appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => {
383      console.log('checkAppAccountSyncEnable, result: ' + data);
384  }).catch((err) => {
385      console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
386  });
387  ```
388
389### setAccountCredential
390
391setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void
392
393设置此应用程序帐号的凭据,使用callback回调异步返回结果。
394
395**系统能力:** SystemCapability.Account.AppAccount
396
397**参数:**
398
399| 参数名            | 类型                        | 必填   | 说明             |
400| -------------- | ------------------------- | ---- | -------------- |
401| name           | string                    | 是    | 应用程序帐户的名称。     |
402| credentialType | string                    | 是    | 要设置的凭据的类型。     |
403| credential     | string                    | 是    | 要设置的凭据。        |
404| callback       | AsyncCallback&lt;void&gt; | 是    | 设置此应用帐号的凭据的回调。 |
405
406**示例:**
407
408  ```js
409  const appAccountManager = account_appAccount.createAppAccountManager();
410  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => {
411      console.log("setAccountCredential err: " + JSON.stringify(err));
412  });
413  ```
414
415### setAccountCredential
416
417setAccountCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;
418
419设置此应用程序帐号的凭据,使用Promise方式异步返回结果。
420
421**系统能力:** SystemCapability.Account.AppAccount
422
423**参数:**
424
425| 参数名            | 类型     | 必填   | 说明         |
426| -------------- | ------ | ---- | ---------- |
427| name           | string | 是    | 应用帐户的名称。   |
428| credentialType | string | 是    | 要设置的凭据的类型。 |
429| credential     | string | 是    | 要设置的凭据。    |
430
431**返回值:**
432
433| 类型                  | 说明                    |
434| :------------------ | :-------------------- |
435| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
436
437**示例:**
438
439  ```js
440  const appAccountManager = account_appAccount.createAppAccountManager();
441  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => {
442      console.log('setAccountCredential Success');
443  }).catch((err) => {
444      console.log("setAccountCredential err: "  + JSON.stringify(err));
445  });
446  ```
447
448### setAccountExtraInfo
449
450setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
451
452设置此应用程序帐号的额外信息,使用callback回调异步返回结果。
453
454**系统能力:** SystemCapability.Account.AppAccount
455
456**参数:**
457
458| 参数名       | 类型                        | 必填   | 说明               |
459| --------- | ------------------------- | ---- | ---------------- |
460| name      | string                    | 是    | 应用帐户的名称。         |
461| extraInfo | string                    | 是    | 要设置的额外信息。        |
462| callback  | AsyncCallback&lt;void&gt; | 是    | 设置此应用帐号的额外信息的回调。 |
463
464**示例:**
465
466  ```js
467  const appAccountManager = account_appAccount.createAppAccountManager();
468  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => {
469      console.log("setAccountExtraInfo err: " + JSON.stringify(err));
470  });
471  ```
472
473### setAccountExtraInfo
474
475setAccountExtraInfo(name: string, extraInfo: string): Promise&lt;void&gt;
476
477设置此应用程序帐号的额外信息,使用Promise方式异步返回结果。
478
479**系统能力:** SystemCapability.Account.AppAccount
480
481**参数:**
482
483| 参数名       | 类型     | 必填   | 说明        |
484| --------- | ------ | ---- | --------- |
485| name      | string | 是    | 应用帐户的名称。  |
486| extraInfo | string | 是    | 要设置的额外信息。 |
487
488**返回值:**
489
490| 类型                  | 说明                    |
491| :------------------ | :-------------------- |
492| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
493
494**示例:**
495
496  ```js
497  const appAccountManager = account_appAccount.createAppAccountManager();
498  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => {
499      console.log('setAccountExtraInfo Success');
500  }).catch((err) => {
501      console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
502  });
503  ```
504
505### setAppAccountSyncEnable
506
507setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
508
509设置指定的应用程序帐号是否允许应用程序数据同步,使用callback回调异步返回结果。
510
511**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
512
513**系统能力:** SystemCapability.Account.AppAccount
514
515**参数:**
516
517| 参数名      | 类型                        | 必填   | 说明                        |
518| -------- | ------------------------- | ---- | ------------------------- |
519| name     | string                    | 是    | 应用帐户的名称。                  |
520| isEnable | boolean                   | 是    | 是否允许应用数据同步。               |
521| callback | AsyncCallback&lt;void&gt; | 是    | 设置指定的应用帐号是否允许应用程序数据同步的回调。 |
522
523**示例:**
524
525  ```js
526  const appAccountManager = account_appAccount.createAppAccountManager();
527  appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => {
528      console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
529  });
530  ```
531
532### setAppAccountSyncEnable
533
534setAppAccountSyncEnable(name: string, isEnable: boolean): Promise&lt;void&gt;
535
536设置指定的应用程序帐号是否允许应用程序数据同步,使用Promise方式异步返回结果。
537
538**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
539
540**系统能力:** SystemCapability.Account.AppAccount
541
542**参数:**
543
544| 参数名      | 类型      | 必填   | 说明          |
545| -------- | ------- | ---- | ----------- |
546| name     | string  | 是    | 应用帐户的名称。    |
547| isEnable | boolean | 是    | 是否允许应用数据同步。 |
548
549**返回值:**
550
551| 类型                  | 说明                    |
552| :------------------ | :-------------------- |
553| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
554
555**示例:**
556
557  ```js
558  const appAccountManager = account_appAccount.createAppAccountManager();
559  appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => {
560      console.log('setAppAccountSyncEnable Success');
561  }).catch((err) => {
562      console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
563  });
564  ```
565
566### setAssociatedData
567
568setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
569
570设置与此应用程序帐号关联的数据,使用callback回调异步返回结果。
571
572**系统能力:** SystemCapability.Account.AppAccount
573
574**参数:**
575
576| 参数名      | 类型                        | 必填   | 说明                |
577| -------- | ------------------------- | ---- | ----------------- |
578| name     | string                    | 是    | 应用帐户的名称。          |
579| key      | string                    | 是    | 要设置的数据的键,密钥可以自定义。 |
580| value    | string                    | 是    | 要设置的数据的值。         |
581| callback | AsyncCallback&lt;void&gt; | 是    | 设置与此应用帐号关联的数据的回调。 |
582
583**示例:**
584
585  ```js
586  const appAccountManager = account_appAccount.createAppAccountManager();
587  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => {
588      console.log("setAssociatedData err: " + JSON.stringify(err));
589  });
590  ```
591
592### setAssociatedData
593
594setAssociatedData(name: string, key: string, value: string): Promise&lt;void&gt;
595
596设置与此应用程序帐号关联的数据,使用Promise方式异步返回结果。
597
598**系统能力:** SystemCapability.Account.AppAccount
599
600**参数:**
601
602| 参数名   | 类型     | 必填   | 说明                |
603| ----- | ------ | ---- | ----------------- |
604| name  | string | 是    | 应用帐户的名称。          |
605| key   | string | 是    | 要设置的数据的键,密钥可以自定义。 |
606| value | string | 是    | 要设置的数据的值。         |
607
608**返回值:**
609
610| 类型                  | 说明                    |
611| :------------------ | :-------------------- |
612| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
613
614**示例:**
615
616  ```js
617  const appAccountManager = account_appAccount.createAppAccountManager();
618  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => {
619      console.log('setAssociatedData Success');
620  }).catch((err) => {
621      console.log("setAssociatedData err: "  + JSON.stringify(err));
622  });
623  ```
624
625### getAccountCredential
626
627getAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void
628
629获取此应用帐号的凭据,使用callback回调异步返回结果。
630
631**系统能力:** SystemCapability.Account.AppAccount
632
633**参数:**
634
635| 参数名            | 类型                          | 必填   | 说明             |
636| -------------- | --------------------------- | ---- | -------------- |
637| name           | string                      | 是    | 应用帐号名称。        |
638| credentialType | string                      | 是    | 要获取的凭据的类型。     |
639| callback       | AsyncCallback&lt;string&gt; | 是    | 获取此应用帐号的凭据的回调。 |
640
641**示例:**
642
643  ```js
644  const appAccountManager = account_appAccount.createAppAccountManager();
645  appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => {
646      console.log("getAccountCredential err: " + JSON.stringify(err));
647      console.log('getAccountCredential result: ' + result);
648  });
649  ```
650
651### getAccountCredential
652
653getAccountCredential(name: string, credentialType: string): Promise&lt;string&gt;
654
655获取此应用程序帐号的凭据,使用Promise方式异步返回结果。
656
657**系统能力:** SystemCapability.Account.AppAccount
658
659**参数:**
660
661| 参数名            | 类型     | 必填   | 说明         |
662| -------------- | ------ | ---- | ---------- |
663| name           | string | 是    | 应用帐号名称。    |
664| credentialType | string | 是    | 要获取的凭据的类型。 |
665
666**返回值:**
667
668| 类型                    | 说明                    |
669| :-------------------- | :-------------------- |
670| Promise&lt;string&gt; | Promise实例,用于获取异步返回结果。 |
671
672**示例:**
673
674  ```js
675  const appAccountManager = account_appAccount.createAppAccountManager();
676  appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => {
677      console.log('getAccountCredential, result: ' + data);
678  }).catch((err) => {
679      console.log("getAccountCredential err: "  + JSON.stringify(err));
680  });
681  ```
682
683### getAccountExtraInfo
684
685getAccountExtraInfo(name: string, callback: AsyncCallback&lt;string&gt;): void
686
687获取此应用帐号的额外信息,使用callback回调异步返回结果。
688
689**系统能力:** SystemCapability.Account.AppAccount
690
691**参数:**
692
693| 参数名      | 类型                          | 必填   | 说明               |
694| -------- | --------------------------- | ---- | ---------------- |
695| name     | string                      | 是    | 应用帐号名称。          |
696| callback | AsyncCallback&lt;string&gt; | 是    | 获取此应用帐号的额外信息的回调。 |
697
698**示例:**
699
700  ```js
701  const appAccountManager = account_appAccount.createAppAccountManager();
702  appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => {
703      console.log("getAccountExtraInfo err: " + JSON.stringify(err));
704      console.log('getAccountExtraInfo result: ' + result);
705  });
706  ```
707
708### getAccountExtraInfo
709
710getAccountExtraInfo(name: string): Promise&lt;string&gt;
711
712获取此应用程序帐号的额外信息,使用Promise方式异步返回结果。
713
714**系统能力:** SystemCapability.Account.AppAccount
715
716**参数:**
717
718| 参数名  | 类型     | 必填   | 说明      |
719| ---- | ------ | ---- | ------- |
720| name | string | 是    | 应用帐号名称。 |
721
722**返回值:**
723
724| 类型                    | 说明                    |
725| :-------------------- | :-------------------- |
726| Promise&lt;string&gt; | Promise实例,用于获取异步返回结果。 |
727
728**示例:**
729
730  ```js
731  const appAccountManager = account_appAccount.createAppAccountManager();
732  appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => {
733      console.log('getAccountExtraInfo, result: ' + data);
734  }).catch((err) => {
735      console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
736  });
737  ```
738
739### getAssociatedData
740
741getAssociatedData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void
742
743获取与此应用程序帐号关联的数据,使用callback回调异步返回结果。
744
745**系统能力:** SystemCapability.Account.AppAccount
746
747**参数:**
748
749| 参数名      | 类型                          | 必填   | 说明                |
750| -------- | --------------------------- | ---- | ----------------- |
751| name     | string                      | 是    | 应用帐号名称。           |
752| key      | string                      | 是    | 要获取的数据的key。       |
753| callback | AsyncCallback&lt;string&gt; | 是    | 获取与此应用帐号关联的数据的回调。 |
754
755**示例:**
756
757  ```js
758  const appAccountManager = account_appAccount.createAppAccountManager();
759  appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => {
760      console.log("getAssociatedData err: " + JSON.stringify(err));
761      console.log('getAssociatedData result: ' + result);
762  });
763  ```
764
765### getAssociatedData
766
767getAssociatedData(name: string, key: string): Promise&lt;string&gt;
768
769获取与此应用程序帐号关联的数据,使用Promise方式异步返回结果。
770
771**系统能力:** SystemCapability.Account.AppAccount
772
773**参数:**
774
775| 参数名  | 类型     | 必填   | 说明          |
776| ---- | ------ | ---- | ----------- |
777| name | string | 是    | 应用帐号名称。     |
778| key  | string | 是    | 要获取的数据的key。 |
779
780**返回值:**
781
782| 类型                    | 说明                    |
783| :-------------------- | :-------------------- |
784| Promise&lt;string&gt; | Promise实例,用于获取异步返回结果。 |
785
786**示例:**
787
788  ```js
789  const appAccountManager = account_appAccount.createAppAccountManager();
790  appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => {
791       console.log('getAssociatedData: ' + data);
792  }).catch((err) => {
793      console.log("getAssociatedData err: "  + JSON.stringify(err));
794  });
795  ```
796
797### getAllAccessibleAccounts
798
799getAllAccessibleAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
800
801获取全部应用已授权帐号信息。
802
803**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,仅系统应用可用。
804
805**系统能力:** SystemCapability.Account.AppAccount
806
807**参数:**
808
809| 参数名      | 类型                                       | 必填   | 说明       |
810| -------- | ---------------------------------------- | ---- | -------- |
811| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | 是    | 应用帐号信息列表 |
812
813**示例:**
814
815  ```js
816  const appAccountManager = account_appAccount.createAppAccountManager();
817  appAccountManager.getAllAccessibleAccounts((err, data)=>{
818  	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
819  	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
820  });
821  ```
822
823### getAllAccessibleAccounts
824
825getAllAccessibleAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
826
827获取全部应用已授权帐号信息。
828
829**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,仅系统应用可用。
830
831**系统能力:** SystemCapability.Account.AppAccount
832
833**参数:**
834
835| 类型                                       | 说明                    |
836| ---------------------------------------- | --------------------- |
837| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise实例,用于获取异步返回结果。 |
838
839**示例:**
840
841  ```js
842  const appAccountManager = account_appAccount.createAppAccountManager();
843  appAccountManager.getAllAccessibleAccounts().then((data) => {
844       console.log('getAllAccessibleAccounts: ' + data);
845  }).catch((err) => {
846      console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
847  });
848  ```
849
850### getAllAccounts
851
852getAllAccounts(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
853
854获取指定应用全部帐号信息。
855
856**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,仅系统应用可用。
857
858**系统能力:** SystemCapability.Account.AppAccount
859
860**参数:**
861
862| 参数名      | 类型                                       | 必填   | 说明       |
863| -------- | ---------------------------------------- | ---- | -------- |
864| owner    | string                                   | 是    | 应用包名称    |
865| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | 是    | 应用帐号信息列表 |
866
867**示例:**
868
869  ```js
870  const appAccountManager = account.createAppAccountManager();
871  const selfBundle = "com.example.actsgetallaaccounts";
872  appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
873  	console.debug("getAllAccounts err:" + JSON.stringify(err));
874  	console.debug("getAllAccounts data:" + JSON.stringify(data));
875  });
876  ```
877
878### getAllAccounts
879
880getAllAccounts(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
881
882获取指定应用全部帐号信息。
883
884**需要权限:** ohos.permission.GET_ALL_APP_ACCOUNTS,仅系统应用可用。
885
886**系统能力:** SystemCapability.Account.AppAccount
887
888**参数:**
889
890| 参数名   | 类型     | 必填   | 说明    |
891| ----- | ------ | ---- | ----- |
892| owner | string | 是    | 应用包名称 |
893
894**参数:**
895
896| 类型                                       | 说明                    |
897| ---------------------------------------- | --------------------- |
898| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise实例,用于获取异步返回结果。 |
899
900**示例:**
901
902  ```js
903  const appAccountManager = account_appAccount.createAppAccountManager();
904  const selfBundle = "com.example.actsgetallaaccounts";
905  appAccountManager.getAllAccounts(selfBundle).then((data) => {
906       console.log('getAllAccounts: ' + data);
907  }).catch((err) => {
908      console.log("getAllAccounts err: "  + JSON.stringify(err));
909  });
910  ```
911
912### on('change')
913
914on(type: 'change', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
915
916订阅指定帐号所有者的帐户变更事件,使用callback回调异步返回结果。
917
918**系统能力:** SystemCapability.Account.AppAccount
919
920**参数:**
921
922| 参数名      | 类型                                       | 必填   | 说明                             |
923| -------- | ---------------------------------------- | ---- | ------------------------------ |
924| type     | 'change'                                 | 是    | 关于帐户更改事件,当帐户所有者更新帐户时,订阅者将收到通知。 |
925| owners   | Array&lt;string&gt;                      | 是    | 指示帐户的所有者。                      |
926| callback | Callback&lt;Array&lt;AppAccountInfo&gt;&gt; | 是    | 订阅指定帐号所有者的帐户变更事件的回调。           |
927
928**示例:**
929
930  ```js
931  const appAccountManager = account.createAppAccountManager();
932  function changeOnCallback(data){
933  	console.debug("receive change data:" + JSON.stringify(data));
934  }
935  try{
936  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
937  }
938  catch(err){
939  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
940  }
941  ```
942
943### off('change')
944
945off(type: 'change', callback?: Callback<Array\<AppAccountInfo>>): void
946
947取消订阅帐号事件,使用callback回调异步返回结果。
948
949**系统能力:** SystemCapability.Account.AppAccount
950
951**参数:**
952
953| 参数名      | 类型                               | 必填   | 说明           |
954| -------- | -------------------------------- | ---- | ------------ |
955| type     | 'change'                         | 是    | 关于帐户更改事件。    |
956| callback | Callback<Array\<AppAccountInfo>> | 否    | 取消订阅帐号事件的回调。 |
957
958**示例:**
959
960  ```js
961  const appAccountManager = account.createAppAccountManager();
962  function changeOnCallback(data){
963  	console.debug("receive change data:" + JSON.stringify(data));
964  	appAccountManager.off('change', function(){
965  		console.debug("off finish");
966  	})
967  }
968  try{
969  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
970  }
971  catch(err){
972  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
973  }
974  ```
975
976### authenticate<sup>8+</sup>
977
978authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
979
980鉴权应用帐户以获取OAuth令牌,使用callback回调异步返回结果。
981
982**系统能力:** SystemCapability.Account.AppAccount
983
984**参数:**
985
986| 参数名      | 类型                    | 必填   | 说明              |
987| -------- | --------------------- | ---- | --------------- |
988| name     | string                | 是    | 要鉴权的应用帐户的名称。    |
989| owner    | string                | 是    | 要鉴权的应用帐户的所有者包名。 |
990| authType | string                | 是    | 鉴权类型。           |
991| options  | {[key: string]: any}  | 是    | 鉴权所需的可选项。       |
992| callback | AuthenticatorCallback | 是    | 认证器回调,用于返回鉴权结果。 |
993
994**示例:**
995
996  ```js
997  import featureAbility from '@ohos.ability.featureAbility';
998
999  function onResultCallback(code, result) {
1000      console.log("resultCode: "  + code);
1001      console.log("result: "  + JSON.stringify(result));
1002  }
1003
1004  function onRequestRedirectedCallback(request) {
1005      let abilityStartSetting = {want: request};
1006      featureAbility.startAbility(abilityStartSetting, (err)=>{
1007          console.log("startAbility err: " + JSON.stringify(err));
1008      });
1009  }
1010
1011  const appAccountManager = account_appAccount.createAppAccountManager();
1012  appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", {}, {
1013    onResult: onResultCallback,
1014    onRequestRedirected: onRequestRedirectedCallback
1015  });
1016  ```
1017
1018### getOAuthToken<sup>8+</sup>
1019
1020getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
1021
1022获取指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。
1023
1024**系统能力:** SystemCapability.Account.AppAccount
1025
1026**参数:**
1027
1028| 参数名      | 类型                          | 必填   | 说明          |
1029| -------- | --------------------------- | ---- | ----------- |
1030| name     | string                      | 是    | 应用帐户的名称。    |
1031| owner    | string                      | 是    | 应用帐户的所有者包名。 |
1032| authType | string                      | 是    | 鉴权类型。       |
1033| callback | AsyncCallback&lt;string&gt; | 是    | 查询结果的回调。    |
1034
1035**示例:**
1036
1037  ```js
1038  const appAccountManager = account_appAccount.createAppAccountManager();
1039  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", (err, data) => {
1040       console.log('getOAuthToken err: ' + JSON.stringify(err));
1041       console.log('getOAuthToken token: ' + data);
1042  });
1043  ```
1044
1045### getOAuthToken<sup>8+</sup>
1046
1047getOAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
1048
1049获取指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。
1050
1051**系统能力:** SystemCapability.Account.AppAccount
1052
1053**参数:**
1054
1055| 参数名      | 类型     | 必填   | 说明          |
1056| -------- | ------ | ---- | ----------- |
1057| name     | string | 是    | 应用帐户的名称。    |
1058| owner    | string | 是    | 应用帐户的所有者包名。 |
1059| authType | string | 是    | 鉴权类型。       |
1060
1061**参数:**
1062
1063| 类型                    | 说明                    |
1064| --------------------- | --------------------- |
1065| Promise&lt;string&gt; | Promise实例,用于获取异步返回结果。 |
1066
1067**示例:**
1068
1069  ```js
1070  const appAccountManager = account_appAccount.createAppAccountManager();
1071  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData").then((data) => {
1072       console.log('getOAuthToken token: ' + data);
1073  }).catch((err) => {
1074      console.log("getOAuthToken err: "  + JSON.stringify(err));
1075  });
1076  ```
1077
1078### setOAuthToken<sup>8+</sup>
1079
1080setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
1081
1082设置指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。
1083
1084**系统能力:** SystemCapability.Account.AppAccount
1085
1086**参数:**
1087
1088| 参数名      | 类型                        | 必填   | 说明       |
1089| -------- | ------------------------- | ---- | -------- |
1090| name     | string                    | 是    | 应用帐户的名称。 |
1091| authType | string                    | 是    | 鉴权类型。    |
1092| token    | string                    | 是    | OAuth令牌。 |
1093| callback | AsyncCallback&lt;void&gt; | 是    | 设置结果的回调。 |
1094
1095**示例:**
1096
1097  ```js
1098  const appAccountManager = account_appAccount.createAppAccountManager();
1099  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
1100      console.log('setOAuthToken err: ' + JSON.stringify(err));
1101  });
1102  ```
1103
1104### setOAuthToken<sup>8+</sup>
1105
1106setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
1107
1108设置指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。
1109
1110**系统能力:** SystemCapability.Account.AppAccount
1111
1112**参数:**
1113
1114| 参数名      | 类型     | 必填   | 说明       |
1115| -------- | ------ | ---- | -------- |
1116| name     | string | 是    | 应用帐户的名称。 |
1117| authType | string | 是    | 鉴权类型。    |
1118| token    | string | 是    | OAuth令牌。 |
1119
1120**参数:**
1121
1122| 类型                  | 说明                    |
1123| ------------------- | --------------------- |
1124| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
1125
1126**示例:**
1127
1128  ```js
1129  const appAccountManager = account_appAccount.createAppAccountManager();
1130  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
1131      console.log('setOAuthToken successfully');
1132  }).catch((err) => {
1133      console.log('setOAuthToken err: ' + JSON.stringify(err));
1134  });
1135  ```
1136
1137### deleteOAuthToken<sup>8+</sup>
1138
1139deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
1140
1141删除指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。
1142
1143**系统能力:** SystemCapability.Account.AppAccount
1144
1145**参数:**
1146
1147| 参数名      | 类型                        | 必填   | 说明           |
1148| -------- | ------------------------- | ---- | ------------ |
1149| name     | string                    | 是    | 应用帐户的名称。     |
1150| owner    | string                    | 是    | 应用帐户的所有者包名。  |
1151| authType | string                    | 是    | 鉴权类型。        |
1152| token    | string                    | 是    | 要删除的OAuth令牌。 |
1153| callback | AsyncCallback&lt;void&gt; | 是    | 删除结果的回调。     |
1154
1155**示例:**
1156
1157  ```js
1158  const appAccountManager = account_appAccount.createAppAccountManager();
1159  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx", (err) => {
1160       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
1161  });
1162  ```
1163
1164### deleteOAuthToken<sup>8+</sup>
1165
1166deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;
1167
1168删除指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。
1169
1170**系统能力:** SystemCapability.Account.AppAccount
1171
1172**参数:**
1173
1174| 参数名      | 类型     | 必填   | 说明           |
1175| -------- | ------ | ---- | ------------ |
1176| name     | string | 是    | 应用帐户的名称。     |
1177| owner    | string | 是    | 应用帐户的所有者包名。  |
1178| authType | string | 是    | 鉴权类型。        |
1179| token    | string | 是    | 要删除的OAuth令牌。 |
1180
1181**参数:**
1182
1183| 类型                  | 说明                    |
1184| ------------------- | --------------------- |
1185| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
1186
1187**示例:**
1188
1189  ```js
1190  const appAccountManager = account_appAccount.createAppAccountManager();
1191  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx").then(() => {
1192       console.log('deleteOAuthToken successfully');
1193  }).catch((err) => {
1194      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
1195  });
1196  ```
1197
1198### setOAuthTokenVisibility<sup>8+</sup>
1199
1200setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
1201
1202设置指定鉴权类型的OAuth令牌对特定应用的可见性,使用callback回调异步返回结果。
1203
1204**系统能力:** SystemCapability.Account.AppAccount
1205
1206**参数:**
1207
1208| 参数名        | 类型                        | 必填   | 说明           |
1209| ---------- | ------------------------- | ---- | ------------ |
1210| name       | string                    | 是    | 应用帐户的名称。     |
1211| authType   | string                    | 是    | 鉴权类型。        |
1212| bundleName | string                    | 是    | 被设置可见性的应用包名。 |
1213| isVisible  | boolean                   | 是    | 是否可见。        |
1214| callback   | AsyncCallback&lt;void&gt; | 是    | 设置结果的回调。     |
1215
1216**示例:**
1217
1218  ```js
1219  const appAccountManager = account_appAccount.createAppAccountManager();
1220  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true, (err) => {
1221       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
1222  });
1223  ```
1224
1225### setOAuthTokenVisibility<sup>8+</sup>
1226
1227setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;
1228
1229设置指定鉴权类型的OAuth令牌对特定应用的可见性,使用Promise方式异步返回结果。
1230
1231**系统能力:** SystemCapability.Account.AppAccount
1232
1233**参数:**
1234
1235| 参数名        | 类型      | 必填   | 说明           |
1236| ---------- | ------- | ---- | ------------ |
1237| name       | string  | 是    | 应用帐户的名称。     |
1238| authType   | string  | 是    | 鉴权类型。        |
1239| bundleName | string  | 是    | 被设置可见性的应用包名。 |
1240| isVisible  | boolean | 是    | 是否可见。        |
1241
1242**参数:**
1243
1244| 类型                  | 说明                    |
1245| ------------------- | --------------------- |
1246| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果。 |
1247
1248**示例:**
1249
1250  ```js
1251  const appAccountManager = account_appAccount.createAppAccountManager();
1252  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true).then(() => {
1253      console.log('setOAuthTokenVisibility successfully');
1254  }).catch((err) => {
1255      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
1256  });
1257  ```
1258
1259### checkOAuthTokenVisibility<sup>8+</sup>
1260
1261checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
1262
1263检查指定鉴权类型的OAuth令牌对特定应用的可见性,使用callback回调异步返回结果。
1264
1265**系统能力:** SystemCapability.Account.AppAccount
1266
1267**参数:**
1268
1269| 参数名        | 类型                           | 必填   | 说明            |
1270| ---------- | ---------------------------- | ---- | ------------- |
1271| name       | string                       | 是    | 应用帐户的名称。      |
1272| authType   | string                       | 是    | 鉴权类型。         |
1273| bundleName | string                       | 是    | 用于检查可见性的应用包名。 |
1274| callback   | AsyncCallback&lt;boolean&gt; | 是    | 检查结果的回调。      |
1275
1276**示例:**
1277
1278  ```js
1279  const appAccountManager = account_appAccount.createAppAccountManager();
1280  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", (err, data) => {
1281      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
1282      console.log('checkOAuthTokenVisibility isVisible: ' + data);
1283  });
1284  ```
1285
1286### checkOAuthTokenVisibility<sup>8+</sup>
1287
1288checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
1289
1290检查指定鉴权类型的OAuth令牌对特定应用的可见性,使用Promise方式异步返回结果。
1291
1292**系统能力:** SystemCapability.Account.AppAccount
1293
1294**参数:**
1295
1296| 参数名        | 类型     | 必填   | 说明            |
1297| ---------- | ------ | ---- | ------------- |
1298| name       | string | 是    | 应用帐户的名称。      |
1299| authType   | string | 是    | 鉴权类型。         |
1300| bundleName | string | 是    | 用于检查可见性的应用包名。 |
1301
1302**参数:**
1303
1304| 类型                     | 说明                    |
1305| ---------------------- | --------------------- |
1306| Promise&lt;boolean&gt; | Promise实例,用于获取异步返回结果。 |
1307
1308**示例:**
1309
1310  ```js
1311  const appAccountManager = account_appAccount.createAppAccountManager();
1312  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo").then((data) => {
1313      console.log('checkOAuthTokenVisibility isVisible: ' + data);
1314  }).catch((err) => {
1315      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
1316  });
1317  ```
1318
1319### getAllOAuthTokens<sup>8+</sup>
1320
1321getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt;): void
1322
1323获取指定应用对调用方全部可见的OAuth令牌,使用callback回调异步返回结果。
1324
1325**系统能力:** SystemCapability.Account.AppAccount
1326
1327**参数:**
1328
1329| 参数名      | 类型                                       | 必填   | 说明          |
1330| -------- | ---------------------------------------- | ---- | ----------- |
1331| name     | string                                   | 是    | 应用帐户的名称。    |
1332| owner    | string                                   | 是    | 应用帐户的所有者包名。 |
1333| callback | AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt; | 是    | 查询结果的回调。    |
1334
1335**示例:**
1336
1337  ```js
1338  const appAccountManager = account_appAccount.createAppAccountManager();
1339  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => {
1340      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
1341      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
1342  });
1343  ```
1344
1345### getAllOAuthTokens<sup>8+</sup>
1346
1347getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
1348
1349获取指定应用帐户对调用方可见的全部OAuth令牌,使用Promise方式异步返回结果。
1350
1351**系统能力:** SystemCapability.Account.AppAccount
1352
1353**参数:**
1354
1355| 参数名   | 类型     | 必填   | 说明          |
1356| ----- | ------ | ---- | ----------- |
1357| name  | string | 是    | 应用帐户的名称。    |
1358| owner | string | 是    | 应用帐户的所有者包名。 |
1359
1360**参数:**
1361
1362| 类型                                       | 说明                    |
1363| ---------------------------------------- | --------------------- |
1364| Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt; | Promise实例,用于获取异步返回结果。 |
1365
1366**示例:**
1367
1368  ```js
1369  const appAccountManager = account_appAccount.createAppAccountManager();
1370  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => {
1371       console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
1372  }).catch((err) => {
1373      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
1374  });
1375  ```
1376
1377### getOAuthList<sup>8+</sup>
1378
1379getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1380
1381获取指定应用帐户和鉴权类型的OAuth令牌的授权列表,使用callback回调异步返回结果。
1382
1383**系统能力:** SystemCapability.Account.AppAccount
1384
1385**参数:**
1386
1387| 参数名      | 类型                                       | 必填   | 说明          |
1388| -------- | ---------------------------------------- | ---- | ----------- |
1389| name     | string                                   | 是    | 应用帐户的名称。    |
1390| owner    | string                                   | 是    | 应用帐户的所有者包名。 |
1391| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 查询结果的回调。    |
1392
1393**示例:**
1394
1395  ```js
1396  const appAccountManager = account_appAccount.createAppAccountManager();
1397  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData", (err, data) => {
1398       console.log('getOAuthList err: ' + JSON.stringify(err));
1399       console.log('getOAuthList data: ' + JSON.stringify(data));
1400  });
1401  ```
1402
1403### getOAuthList<sup>8+</sup>
1404
1405getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
1406
1407获取指定应用帐户和鉴权类型的OAuth令牌的授权列表,使用Promise方式异步返回结果。
1408
1409**系统能力:** SystemCapability.Account.AppAccount
1410
1411**参数:**
1412
1413| 参数名   | 类型     | 必填   | 说明          |
1414| ----- | ------ | ---- | ----------- |
1415| name  | string | 是    | 应用帐户的名称。    |
1416| owner | string | 是    | 应用帐户的所有者包名。 |
1417
1418**参数:**
1419
1420| 类型                                 | 说明                    |
1421| ---------------------------------- | --------------------- |
1422| Promise&lt;Array&lt;string&gt;&gt; | Promise实例,用于获取异步返回结果。 |
1423
1424**示例:**
1425
1426  ```js
1427  const appAccountManager = account_appAccount.createAppAccountManager();
1428  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData").then((data) => {
1429       console.log('getOAuthList data: ' + JSON.stringify(data));
1430  }).catch((err) => {
1431      console.log("getOAuthList err: "  + JSON.stringify(err));
1432  });
1433  ```
1434
1435### getAuthenticatorCallback<sup>8+</sup>
1436
1437getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
1438
1439获取鉴权会话的认证器回调,使用callback回调异步返回结果。
1440
1441**系统能力:** SystemCapability.Account.AppAccount
1442
1443**参数:**
1444
1445| 参数名       | 类型                                       | 必填   | 说明       |
1446| --------- | ---------------------------------------- | ---- | -------- |
1447| sessionId | string                                   | 是    | 鉴权会话的标识。 |
1448| callback  | AsyncCallback&lt;AuthenticatorCallback&gt; | 是    | 查询结果的回调。 |
1449
1450**示例:**
1451
1452  ```js
1453  const appAccountManager = account_appAccount.createAppAccountManager();
1454  featureAbility.getWant((err, want) => {
1455    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
1456    appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
1457        if (err.code != account_appAccount.ResultCode.SUCCESS) {
1458            console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1459            return;
1460        }
1461        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1462                      [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1463                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1464                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1465        callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1466    });
1467  });
1468  ```
1469
1470### getAuthenticatorCallback<sup>8+</sup>
1471
1472getAuthenticatorCallback(sessionId: string): Promise&lt;AuthenticatorCallback&gt;
1473
1474获取鉴权会话的认证器回调,使用Promise方式异步返回结果。
1475
1476**系统能力:** SystemCapability.Account.AppAccount
1477
1478**参数:**
1479
1480| 参数名       | 类型     | 必填   | 说明       |
1481| --------- | ------ | ---- | -------- |
1482| sessionId | string | 是    | 鉴权会话的标识。 |
1483
1484**参数:**
1485
1486| 类型                                   | 说明                    |
1487| ------------------------------------ | --------------------- |
1488| Promise&lt;AuthenticatorCallback&gt; | Promise实例,用于获取异步返回结果。 |
1489
1490**示例:**
1491
1492  ```js
1493  const appAccountManager = account_appAccount.createAppAccountManager();
1494  featureAbility.getWant().then((want) => {
1495      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
1496      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
1497          var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1498                        [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1499                        [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1500                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1501          callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1502      }).catch((err) => {
1503          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1504      });
1505  }).catch((err) => {
1506      console.log("getWant err: "  + JSON.stringify(err));
1507  });
1508  ```
1509
1510### getAuthenticatorInfo<sup>8+</sup>
1511
1512getAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void
1513
1514获取指定应用帐户的认证器信息,使用callback回调异步返回结果。
1515
1516**系统能力:** SystemCapability.Account.AppAccount
1517
1518**参数:**
1519
1520| 参数名      | 类型                                     | 必填   | 说明          |
1521| -------- | -------------------------------------- | ---- | ----------- |
1522| owner    | string                                 | 是    | 应用帐户的所有者包名。 |
1523| callback | AsyncCallback&lt;AuthenticatorInfo&gt; | 是    | 查询结果的回调。    |
1524
1525**示例:**
1526
1527  ```js
1528  const appAccountManager = account_appAccount.createAppAccountManager();
1529  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => {
1530      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
1531      console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
1532  });
1533  ```
1534
1535### getAuthenticatorInfo<sup>8+</sup>
1536
1537getAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;
1538
1539获取指定应用帐户的认证器信息,使用Promise方式异步返回结果。
1540
1541**系统能力:** SystemCapability.Account.AppAccount
1542
1543**参数:**
1544
1545| 参数名   | 类型     | 必填   | 说明          |
1546| ----- | ------ | ---- | ----------- |
1547| owner | string | 是    | 应用帐户的所有者包名。 |
1548
1549**参数:**
1550
1551| 类型                               | 说明                    |
1552| -------------------------------- | --------------------- |
1553| Promise&lt;AuthenticatorInfo&gt; | Promise实例,用于获取异步返回结果。 |
1554
1555**示例:**
1556
1557  ```js
1558  const appAccountManager = account_appAccount.createAppAccountManager();
1559  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => {
1560       console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
1561  }).catch((err) => {
1562      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
1563  });
1564  ```
1565
1566## AppAccountInfo
1567
1568表示应用帐号信息。
1569
1570**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount1571
1572| 参数名   | 类型     | 必填   | 说明          |
1573| ----- | ------ | ---- | ----------- |
1574| owner | string | 是    | 应用帐户的所有者包名。 |
1575| name  | string | 是    | 应用帐户的名称。    |
1576
1577## OAuthTokenInfo<sup>8+</sup>
1578
1579表示OAuth令牌信息。
1580
1581**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount1582
1583| 参数名      | 类型     | 必填   | 说明       |
1584| -------- | ------ | ---- | -------- |
1585| authType | string | 是    | 令牌的鉴权类型。 |
1586| token    | string | 是    | 令牌的取值。   |
1587
1588## AuthenticatorInfo<sup>8+</sup>
1589
1590表示OAuth认证器信息。
1591
1592**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount1593
1594| 参数名     | 类型     | 必填   | 说明         |
1595| ------- | ------ | ---- | ---------- |
1596| owner   | string | 是    | 认证器的所有者包名。 |
1597| iconId  | number | 是    | 认证器的图标标识。  |
1598| labelId | number | 是    | 认证器的标签标识。  |
1599
1600## Constants<sup>8+</sup>
1601
1602表示常量的枚举。
1603
1604**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount1605
1606| 名称                            | 默认值                    | 描述            |
1607| ----------------------------- | ---------------------- | ------------- |
1608| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | 表示操作_隐式添加帐号。  |
1609| ACTION_AUTHENTICATE           | "authenticate"         | 表示操作_鉴权。      |
1610| KEY_NAME                      | "name"                 | 表示键名_应用帐户名称。  |
1611| KEY_OWNER                     | "owner"                | 表示键名_应用帐户所有者。 |
1612| KEY_TOKEN                     | "token"                | 表示键名_令牌。      |
1613| KEY_ACTION                    | "action"               | 表示键名_操作。      |
1614| KEY_AUTH_TYPE                 | "authType"             | 表示键名_鉴权类型。    |
1615| KEY_SESSION_ID                | "sessionId"            | 表示键名_会话标识。    |
1616| KEY_CALLER_PID                | "callerPid"            | 表示键名_调用方PID。  |
1617| KEY_CALLER_UID                | "callerUid"            | 表示键名_调用方UID。  |
1618| KEY_CALLER_BUNDLE_NAME        | "callerBundleName"     | 表示键名_调用方包名。   |
1619
1620## ResultCode<sup>8+</sup>
1621
1622表示返回码的枚举。
1623
1624**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount1625
1626| 名称                                  | 默认值   | 描述           |
1627| ----------------------------------- | ----- | ------------ |
1628| SUCCESS                             | 0     | 表示操作成功。      |
1629| ERROR_ACCOUNT_NOT_EXIST             | 10001 | 表示应用帐户不存在。   |
1630| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | 表示应用帐户服务异常。  |
1631| ERROR_INVALID_PASSWORD              | 10003 | 表示密码无效。      |
1632| ERROR_INVALID_REQUEST               | 10004 | 表示请求无效。      |
1633| ERROR_INVALID_RESPONSE              | 10005 | 表示响应无效。      |
1634| ERROR_NETWORK_EXCEPTION             | 10006 | 表示网络异常。      |
1635| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | 表示认证器不存在。    |
1636| ERROR_OAUTH_CANCELED                | 10008 | 表示鉴权取消。      |
1637| ERROR_OAUTH_LIST_TOO_LARGE          | 10009 | 表示开放授权列表过大。  |
1638| ERROR_OAUTH_SERVICE_BUSY            | 10010 | 表示开放授权服务忙碌。  |
1639| ERROR_OAUTH_SERVICE_EXCEPTION       | 10011 | 表示开放授权服务异常。  |
1640| ERROR_OAUTH_SESSION_NOT_EXIST       | 10012 | 表示鉴权会话不存在。   |
1641| ERROR_OAUTH_TIMEOUT                 | 10013 | 表示鉴权超时。      |
1642| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | 表示开放授权令牌不存在。 |
1643| ERROR_OAUTH_TOKEN_TOO_MANY          | 10015 | 表示开放授权令牌过多。  |
1644| ERROR_OAUTH_UNSUPPORT_ACTION        | 10016 | 表示不支持的鉴权操作。  |
1645| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE     | 10017 | 表示不支持的鉴权类型。  |
1646| ERROR_PERMISSION_DENIED             | 10018 | 表示权限不足。      |
1647
1648## AuthenticatorCallback<sup>8+</sup>
1649
1650OAuth认证器回调接口。
1651
1652### onResult<sup>8+</sup>
1653
1654onResult: (code: number, result: {[key: string]: any}) =&gt; void
1655
1656通知鉴权结果。
1657
1658**系统能力:** SystemCapability.Account.AppAccount
1659
1660**参数:**
1661| 参数名    | 类型                   | 必填   | 说明     |
1662| ------ | -------------------- | ---- | ------ |
1663| code   | number               | 是    | 鉴权结果码。 |
1664| result | {[key: string]: any} | 是    | 鉴权结果。  |
1665
1666**示例:**
1667
1668  ```js
1669  const appAccountManager = account_appAccount.createAppAccountManager();
1670  var sessionId = "1234";
1671  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
1672      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1673                    [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1674                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1675                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1676      callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1677  }).catch((err) => {
1678      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1679  });
1680  ```
1681
1682### onRequestRedirected<sup>8+</sup>
1683
1684onRequestRedirected: (request: Want) =&gt; void
1685
1686通知鉴权请求被跳转。
1687
1688**系统能力:** SystemCapability.Account.AppAccount
1689
1690**参数:**
1691| 参数名     | 类型   | 必填   | 说明         |
1692| ------- | ---- | ---- | ---------- |
1693| request | Want | 是    | 用于跳转的请求信息。 |
1694
1695**示例:**
1696
1697  ```js
1698  class MyAuthenticator extends account_appAccount.Authenticator {
1699      addAccountImplicitly(authType, callerBundleName, options, callback) {
1700          callback.onRequestRedirected({
1701              bundleName: "com.example.ohos.accountjsdemo",
1702              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
1703          });
1704      }
1705
1706      authenticate(name, authType, callerBundleName, options, callback) {
1707          var result = {[account_appAccount.Constants.KEY_NAME]: name,
1708                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
1709                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1710          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
1711      }
1712  }
1713  ```
1714
1715## Authenticator<sup>8+</sup>
1716
1717OAuth认证器基类。
1718
1719### addAccountImplicitly<sup>8+</sup>
1720
1721addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
1722
1723根据指定的鉴权类型和可选项,隐式地添加应用帐户,并使用callback回调异步返回结果。
1724
1725**系统能力:** SystemCapability.Account.AppAccount
1726
1727**参数:**
1728| 参数名              | 类型                    | 必填   | 说明              |
1729| ---------------- | --------------------- | ---- | --------------- |
1730| authType         | string                | 是    | 应用帐户的鉴权类型。      |
1731| callerBundleName | string                | 是    | 鉴权请求方的包名。       |
1732| options          | {[key: string]: any}  | 是    | 鉴权所需要的可选项。      |
1733| callback         | AuthenticatorCallback | 是    | 认证器回调,用于返回鉴权结果。 |
1734
1735### authenticate<sup>8+</sup>
1736
1737authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
1738
1739对应用帐户进行鉴权,获取OAuth令牌,并使用callback回调异步返回结果。
1740
1741**系统能力:** SystemCapability.Account.AppAccount
1742
1743**参数:**
1744| 接口名              | 类型                    | 必填   | 说明              |
1745| ---------------- | --------------------- | ---- | --------------- |
1746| name             | string                | 是    | 应用帐户的名称。        |
1747| authType         | string                | 是    | 应用帐户的鉴权类型。      |
1748| callerBundleName | string                | 是    | 鉴权请求方的包名。       |
1749| options          | {[key: string]: any}  | 是    | 鉴权所需要的可选项。      |
1750| callback         | AuthenticatorCallback | 是    | 认证器回调,用于返回鉴权结果。 |
1751
1752**示例:**
1753
1754  ```js
1755  class MyAuthenticator extends account_appAccount.Authenticator {
1756      addAccountImplicitly(authType, callerBundleName, options, callback) {
1757          callback.onRequestRedirected({
1758              bundleName: "com.example.ohos.accountjsdemo",
1759              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
1760          });
1761      }
1762
1763      authenticate(name, authType, callerBundleName, options, callback) {
1764          var result = {[account_appAccount.Constants.KEY_NAME]: name,
1765                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
1766                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1767          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
1768      }
1769  }
1770
1771  export default {
1772      onConnect(want) {
1773          return new MyAuthenticator();
1774      }
1775  }
1776  ```