js-apis-appAccount.md 67.1 KB
Newer Older
A
annie_wangli 已提交
1
#  	App Account Management
A
annie_wangli 已提交
2

A
annie_wangli 已提交
3
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
A
annie_wangli 已提交
4 5 6 7 8
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.


## Modules to Import

Z
zhangalong 已提交
9
```js
A
annie_wangli 已提交
10 11 12 13 14 15
import account_appAccount from '@ohos.account.appAccount';
```


## account_appAccount.createAppAccountManager

A
annie_wangli 已提交
16
createAppAccountManager(): AppAccountManager
A
annie_wangli 已提交
17 18 19

Creates an **AppAccountManager** instance.

A
annie_wangli 已提交
20
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
21

A
annie_wangli 已提交
22
**Return Value**
A
annie_wangli 已提交
23 24
| Type               | Description          |
| ----------------- | ------------ |
A
annie_wangli 已提交
25 26 27
| AppAccountManager | **AppAccountManager** instance created.|

**Example**
Z
zhangalong 已提交
28
  ```js
A
annie_wangli 已提交
29 30 31 32 33
  var appAccountManager = account.createAppAccountManager();
  ```

## AppAccountManager

A
annie_wangli 已提交
34
Provides methods to manage app accounts.
A
annie_wangli 已提交
35 36 37

### addAccount

A
annie_wangli 已提交
38
addAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
39

A
annie_wangli 已提交
40
Adds an app account to the account management service. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
41

A
annie_wangli 已提交
42
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
43

A
annie_wangli 已提交
44
**Parameters**
A
annie_wangli 已提交
45

A
annie_wangli 已提交
46 47 48 49
| Name     | Type                       | Mandatory  | Description                   |
| -------- | ------------------------- | ---- | --------------------- |
| name     | string                    | Yes   | Name of the app account to add.         |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is added.|
A
annie_wangli 已提交
50

A
annie_wangli 已提交
51
**Example**
A
annie_wangli 已提交
52

Z
zhangalong 已提交
53
  ```js
A
annie_wangli 已提交
54 55 56 57 58 59 60 61
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("WangWu", (err) => { 
      console.log("addAccount err: " + JSON.stringify(err));
  });
  ```

### addAccount

A
annie_wangli 已提交
62
addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
63

A
annie_wangli 已提交
64
Adds an app account and its additional information to the account management service. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
65

A
annie_wangli 已提交
66
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
67

A
annie_wangli 已提交
68
**Parameters**
A
annie_wangli 已提交
69

A
annie_wangli 已提交
70 71 72 73 74
| Name      | Type                       | Mandatory  | Description                                      |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| name      | string                    | Yes   | Name of the app account to add.                            |
| extraInfo | string                    | Yes   | Additional information (for example, token) of the app account to add. The additional information cannot contain sensitive information about the app account.|
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account and its additional information are added.           |
A
annie_wangli 已提交
75

A
annie_wangli 已提交
76
**Example**
A
annie_wangli 已提交
77

Z
zhangalong 已提交
78
  ```js
A
annie_wangli 已提交
79 80 81 82 83 84 85 86 87 88
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("LiSi", "token101", (err) => { 
      console.log("addAccount err: " + JSON.stringify(err));
  });
  ```



### addAccount

A
annie_wangli 已提交
89
addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;
A
annie_wangli 已提交
90

A
annie_wangli 已提交
91
Adds an app account and its additional information to the account management service. This method uses a promise to return the result.
A
annie_wangli 已提交
92

A
annie_wangli 已提交
93
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
94

A
annie_wangli 已提交
95
**Parameters**
A
annie_wangli 已提交
96

A
annie_wangli 已提交
97 98 99 100
| Name      | Type    | Mandatory  | Description                              |
| --------- | ------ | ---- | -------------------------------- |
| name      | string | Yes   | Name of the app account to add.                    |
| extraInfo | string | Yes   | Additional information of the app account to add. The additional information cannot contain sensitive information about the app account.|
A
annie_wangli 已提交
101

A
annie_wangli 已提交
102
**Return Value**
A
annie_wangli 已提交
103

A
annie_wangli 已提交
104 105
| Type                 | Description                   |
| ------------------- | --------------------- |
A
annie_wangli 已提交
106
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
107

A
annie_wangli 已提交
108
**Example**
A
annie_wangli 已提交
109

Z
zhangalong 已提交
110
  ```js
A
annie_wangli 已提交
111 112 113 114 115 116 117 118
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("LiSi", "token101").then(()=> { 
      console.log('addAccount Success');
  }).catch((err) => {
      console.log("addAccount err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
119 120
### addAccountImplicitly<sup>8+</sup>

A
annie_wangli 已提交
121
addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
122 123 124

Implicitly adds an app account based on the specified account owner, authentication type, and options. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
125
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
126

A
annie_wangli 已提交
127
**Parameters**
A
annie_wangli 已提交
128

A
annie_wangli 已提交
129 130 131 132 133 134
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
| owner    | string                | Yes   | Bundle name of the app account to add.|
| authType | string                | Yes   | Authentication type of the app account to add. |
| options  | {[key: string]: any}  | Yes   | Options for the authentication.     |
| callback | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
135

A
annie_wangli 已提交
136
**Example**
A
annie_wangli 已提交
137

Z
zhangalong 已提交
138
  ```js
A
annie_wangli 已提交
139
  import featureAbility from '@ohos.ability.featureAbility';
A
annie_wangli 已提交
140

A
annie_wangli 已提交
141 142 143 144
  function onResultCallback(code, result) {
      console.log("resultCode: "  + code);
      console.log("result: "  + JSON.stringify(result));
  }
A
annie_wangli 已提交
145

A
annie_wangli 已提交
146 147 148 149 150 151
  function onRequestRedirectedCallback(request) {
      let abilityStartSetting = {want: request};
      featureAbility.startAbility(abilityStartSetting, (err)=>{
          console.log("startAbility err: " + JSON.stringify(err));
      });
  }
A
annie_wangli 已提交
152

A
annie_wangli 已提交
153 154 155 156 157 158 159
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccountImplicitly("LiSi", "readAge", {}, {
      onResult: onResultCallback,
      onRequestRedirected: onRequestRedirectedCallback
  });
  ```

A
annie_wangli 已提交
160 161
### deleteAccount

A
annie_wangli 已提交
162
deleteAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
163

A
annie_wangli 已提交
164
Deletes an app account from the account management service. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
165

A
annie_wangli 已提交
166
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
167

A
annie_wangli 已提交
168
**Parameters**
A
annie_wangli 已提交
169

A
annie_wangli 已提交
170 171 172 173
| Name     | Type                       | Mandatory  | Description               |
| -------- | ------------------------- | ---- | ----------------- |
| name     | string                    | Yes   | Name of the app account to delete.     |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is deleted.|
A
annie_wangli 已提交
174 175

**Example**
A
annie_wangli 已提交
176

Z
zhangalong 已提交
177
  ```js
A
annie_wangli 已提交
178 179 180 181 182 183 184 185
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccount("ZhaoLiu", (err) => { 
      console.log("deleteAccount err: " + JSON.stringify(err));
   });
  ```

### deleteAccount

A
annie_wangli 已提交
186
deleteAccount(name: string): Promise&lt;void&gt;
A
annie_wangli 已提交
187

A
annie_wangli 已提交
188
Deletes an app account from the account management service. This method uses a promise to return the result.
A
annie_wangli 已提交
189

A
annie_wangli 已提交
190 191 192
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
193

A
annie_wangli 已提交
194 195 196
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| name | string | Yes   | Name of the app account to delete.|
A
annie_wangli 已提交
197

A
annie_wangli 已提交
198
**Return Value**
A
annie_wangli 已提交
199

A
annie_wangli 已提交
200 201
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
202
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
203

A
annie_wangli 已提交
204
**Example**
A
annie_wangli 已提交
205

Z
zhangalong 已提交
206
  ```js
A
annie_wangli 已提交
207 208 209 210 211 212 213 214 215 216
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccount("ZhaoLiu").then(() => { 
        console.log('deleteAccount Success');
   }).catch((err) => {
      console.log("deleteAccount err: "  + JSON.stringify(err));
  });
  ```

### disableAppAccess

A
annie_wangli 已提交
217
disableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
218

A
annie_wangli 已提交
219
Disables an app account from accessing an application with the given bundle name. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
220

A
annie_wangli 已提交
221
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
222

A
annie_wangli 已提交
223
**Parameters**
A
annie_wangli 已提交
224

A
annie_wangli 已提交
225 226 227 228 229
| Name       | Type                       | Mandatory  | Description                             |
| ---------- | ------------------------- | ---- | ------------------------------- |
| name       | string                    | Yes   | App account name.              |
| bundleName | string                    | Yes   | Bundle name of an app.                      |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is disabled from accessing the application with the given bundle name.|
A
annie_wangli 已提交
230 231

**Example**
A
annie_wangli 已提交
232

Z
zhangalong 已提交
233
  ```js
A
annie_wangli 已提交
234
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
235
  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { 
A
annie_wangli 已提交
236 237 238 239 240 241
      console.log("disableAppAccess err: " + JSON.stringify(err));
  });
  ```

### disableAppAccess

A
annie_wangli 已提交
242
disableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
A
annie_wangli 已提交
243

A
annie_wangli 已提交
244
Disables an app account from accessing an application with the given bundle name. This method uses a promise to return the result.
A
annie_wangli 已提交
245

A
annie_wangli 已提交
246 247 248
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
249

A
annie_wangli 已提交
250 251 252 253
| Name       | Type    | Mandatory  | Description               |
| ---------- | ------ | ---- | ----------------- |
| name       | string | Yes   | App account name.|
| bundleName | string | Yes   | Bundle name of an app.        |
A
annie_wangli 已提交
254

A
annie_wangli 已提交
255
**Return Value**
A
annie_wangli 已提交
256

A
annie_wangli 已提交
257 258
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
259
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
260

A
annie_wangli 已提交
261
**Example**
A
annie_wangli 已提交
262

Z
zhangalong 已提交
263
  ```js
A
annie_wangli 已提交
264
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
265
  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { 
A
annie_wangli 已提交
266 267 268 269 270 271 272 273
      console.log('disableAppAccess Success');
  }).catch((err) => {
      console.log("disableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### enableAppAccess

A
annie_wangli 已提交
274
enableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
275

A
annie_wangli 已提交
276
Enables an app account to access an application with the given bundle name. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
277

A
annie_wangli 已提交
278 279 280
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
281

A
annie_wangli 已提交
282 283 284 285 286
| Name       | Type                       | Mandatory  | Description                             |
| ---------- | ------------------------- | ---- | ------------------------------- |
| name       | string                    | Yes   | App account name.                        |
| bundleName | string                    | Yes   | Bundle name of an app.                      |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is enabled to access the application with the given bundle name.|
A
annie_wangli 已提交
287

A
annie_wangli 已提交
288
**Example**
A
annie_wangli 已提交
289

Z
zhangalong 已提交
290
  ```js
A
annie_wangli 已提交
291
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
292
  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { 
A
annie_wangli 已提交
293 294 295 296 297 298
      console.log("enableAppAccess: " + JSON.stringify(err));
   });
  ```

### enableAppAccess

A
annie_wangli 已提交
299
enableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
A
annie_wangli 已提交
300

A
annie_wangli 已提交
301
Enables an app account to access an application with the given bundle name. This method uses a promise to return the result.
A
annie_wangli 已提交
302

A
annie_wangli 已提交
303
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
304

A
annie_wangli 已提交
305
**Parameters**
A
annie_wangli 已提交
306

A
annie_wangli 已提交
307 308 309 310
| Name       | Type    | Mandatory  | Description       |
| ---------- | ------ | ---- | --------- |
| name       | string | Yes   | App account name.  |
| bundleName | string | Yes   | Bundle name of an app.|
A
annie_wangli 已提交
311

A
annie_wangli 已提交
312
**Return Value**
A
annie_wangli 已提交
313

A
annie_wangli 已提交
314 315
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
316 317 318
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
319

Z
zhangalong 已提交
320
  ```js
Z
zengyawen 已提交
321
  app_account_instance.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { 
A
annie_wangli 已提交
322 323 324 325 326 327 328 329
       console.log('enableAppAccess Success');
  }).catch((err) => {
      console.log("enableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### checkAppAccountSyncEnable

A
annie_wangli 已提交
330
checkAppAccountSyncEnable(name: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
331

A
annie_wangli 已提交
332
Checks whether an app account allows application data synchronization. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
333

A
annie_wangli 已提交
334 335 336
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
337

A
annie_wangli 已提交
338
**Parameters**
A
annie_wangli 已提交
339

A
annie_wangli 已提交
340 341 342 343
| Name     | Type                          | Mandatory  | Description                    |
| -------- | ---------------------------- | ---- | ---------------------- |
| name     | string                       | Yes   | App account name.               |
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback used to return whether the app account allows application data synchronization.|
A
annie_wangli 已提交
344

A
annie_wangli 已提交
345
**Example**
A
annie_wangli 已提交
346

Z
zhangalong 已提交
347
  ```js
A
annie_wangli 已提交
348 349 350 351 352 353 354 355 356
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { 
      console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
      console.log('checkAppAccountSyncEnable result: ' + result);
  });
  ```

### checkAppAccountSyncEnable

A
annie_wangli 已提交
357
checkAppAccountSyncEnable(name: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
358

A
annie_wangli 已提交
359
Checks whether an app account allows application data synchronization. This method uses a promise to return the result.
A
annie_wangli 已提交
360

A
annie_wangli 已提交
361
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)
A
annie_wangli 已提交
362

A
annie_wangli 已提交
363
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
364

A
annie_wangli 已提交
365
**Parameters**
A
annie_wangli 已提交
366

A
annie_wangli 已提交
367 368 369
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | App account name.|
A
annie_wangli 已提交
370

A
annie_wangli 已提交
371
**Return Value**
A
annie_wangli 已提交
372

A
annie_wangli 已提交
373 374
| Type                    | Description                   |
| :--------------------- | :-------------------- |
A
annie_wangli 已提交
375 376 377
| Promise&lt;boolean&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
378

Z
zhangalong 已提交
379
  ```js
A
annie_wangli 已提交
380 381 382 383 384 385 386 387 388 389
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { 
      console.log('checkAppAccountSyncEnable, result: ' + data);
  }).catch((err) => {
      console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAccountCredential

A
annie_wangli 已提交
390
setAccountCredential(name: string, credentialType: string, credential: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
391

A
annie_wangli 已提交
392
Sets a credential for an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
393

A
annie_wangli 已提交
394 395 396
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
397

A
annie_wangli 已提交
398 399 400 401 402 403
| Name           | Type                       | Mandatory  | Description            |
| -------------- | ------------------------- | ---- | -------------- |
| name           | string                    | Yes   | App account name.    |
| credentialType | string                    | Yes   | Type of the credential to set.    |
| credential     | string                    | Yes   | Credential to set.       |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when a credential is set for the specified app account.|
A
annie_wangli 已提交
404

A
annie_wangli 已提交
405
**Example**
A
annie_wangli 已提交
406

Z
zhangalong 已提交
407
  ```js
A
annie_wangli 已提交
408 409 410 411 412 413 414 415
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { 
      console.log("setAccountCredential err: " + JSON.stringify(err));
  });
  ```

### setAccountCredential

A
annie_wangli 已提交
416
setAccountCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;
A
annie_wangli 已提交
417

A
annie_wangli 已提交
418
Sets a credential for an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
419

A
annie_wangli 已提交
420
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
421

A
annie_wangli 已提交
422
**Parameters**
A
annie_wangli 已提交
423

A
annie_wangli 已提交
424 425 426 427 428
| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | App account name.  |
| credentialType | string | Yes   | Type of the credential to set.|
| credential     | string | Yes   | Credential to set.   |
A
annie_wangli 已提交
429

A
annie_wangli 已提交
430
**Return Value**
A
annie_wangli 已提交
431

A
annie_wangli 已提交
432 433
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
434 435 436
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
437

Z
zhangalong 已提交
438
  ```js
A
annie_wangli 已提交
439 440 441 442 443 444 445 446 447 448
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { 
      console.log('setAccountCredential Success');
  }).catch((err) => {
      console.log("setAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo

A
annie_wangli 已提交
449
setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
450

A
annie_wangli 已提交
451
Sets additional information for an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
452

A
annie_wangli 已提交
453 454 455
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
456

A
annie_wangli 已提交
457 458 459 460 461
| Name      | Type                       | Mandatory  | Description              |
| --------- | ------------------------- | ---- | ---------------- |
| name      | string                    | Yes   | App account name.        |
| extraInfo | string                    | Yes   | Additional information to set.       |
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when additional information is set for the specified app account.|
A
annie_wangli 已提交
462

A
annie_wangli 已提交
463
**Example**
A
annie_wangli 已提交
464

Z
zhangalong 已提交
465
  ```js
A
annie_wangli 已提交
466 467 468 469 470 471 472 473
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { 
      console.log("setAccountExtraInfo err: " + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo

A
annie_wangli 已提交
474
setAccountExtraInfo(name: string, extraInfo: string): Promise&lt;void&gt;
A
annie_wangli 已提交
475

A
annie_wangli 已提交
476
Sets additional information for an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
477

A
annie_wangli 已提交
478
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
479

A
annie_wangli 已提交
480
**Parameters**
A
annie_wangli 已提交
481

A
annie_wangli 已提交
482 483 484 485
| Name      | Type    | Mandatory  | Description       |
| --------- | ------ | ---- | --------- |
| name      | string | Yes   | App account name. |
| extraInfo | string | Yes   | Additional information to set.|
A
annie_wangli 已提交
486

A
annie_wangli 已提交
487
**Return Value**
A
annie_wangli 已提交
488

A
annie_wangli 已提交
489 490
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
491 492 493
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
494

Z
zhangalong 已提交
495
  ```js
A
annie_wangli 已提交
496 497 498 499 500 501 502 503 504 505
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { 
      console.log('setAccountExtraInfo Success');
  }).catch((err) => {
      console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable

A
annie_wangli 已提交
506
setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
507

A
annie_wangli 已提交
508
Sets whether to enable application data synchronization for an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
509

A
annie_wangli 已提交
510 511 512
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
513

A
annie_wangli 已提交
514
**Parameters**
A
annie_wangli 已提交
515

A
annie_wangli 已提交
516 517 518 519 520
| Name     | Type                       | Mandatory  | Description                       |
| -------- | ------------------------- | ---- | ------------------------- |
| name     | string                    | Yes   | App account name.                 |
| isEnable | boolean                   | Yes   | Whether to enable app data synchronization.              |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when application data synchronization is enabled or disabled for the app account.|
A
annie_wangli 已提交
521

A
annie_wangli 已提交
522
**Example**
A
annie_wangli 已提交
523

Z
zhangalong 已提交
524
  ```js
A
annie_wangli 已提交
525 526 527 528 529 530 531 532
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { 
      console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable

A
annie_wangli 已提交
533
setAppAccountSyncEnable(name: string, isEnable: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
534

A
annie_wangli 已提交
535
Sets whether to enable application data synchronization for an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
536

A
annie_wangli 已提交
537 538 539
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
540

A
annie_wangli 已提交
541
**Parameters**
A
annie_wangli 已提交
542

A
annie_wangli 已提交
543 544 545 546
| Name     | Type     | Mandatory  | Description         |
| -------- | ------- | ---- | ----------- |
| name     | string  | Yes   | App account name.   |
| isEnable | boolean | Yes   | Whether to enable app data synchronization.|
A
annie_wangli 已提交
547

A
annie_wangli 已提交
548
**Return Value**
A
annie_wangli 已提交
549

A
annie_wangli 已提交
550 551
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
552
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
553

A
annie_wangli 已提交
554
**Example**
A
annie_wangli 已提交
555

Z
zhangalong 已提交
556
  ```js
A
annie_wangli 已提交
557 558 559 560 561 562 563 564 565 566
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { 
      console.log('setAppAccountSyncEnable Success');
  }).catch((err) => {
      console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAssociatedData

A
annie_wangli 已提交
567
setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
568

A
annie_wangli 已提交
569
Sets data to be associated with an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
570

A
annie_wangli 已提交
571
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
572

A
annie_wangli 已提交
573
**Parameters**
A
annie_wangli 已提交
574

A
annie_wangli 已提交
575 576 577 578 579 580
| Name     | Type                       | Mandatory  | Description               |
| -------- | ------------------------- | ---- | ----------------- |
| name     | string                    | Yes   | App account name.         |
| key      | string                    | Yes   | Key of the data to set. The private key can be customized.|
| value    | string                    | Yes   | Value of the data to be set.        |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the data associated with the specified app account is set.|
A
annie_wangli 已提交
581 582

**Example**
A
annie_wangli 已提交
583

Z
zhangalong 已提交
584
  ```js
A
annie_wangli 已提交
585 586 587 588 589 590 591
  app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) => { 
      console.log("setAssociatedData err: " + JSON.stringify(err));
  });
  ```

### setAssociatedData

A
annie_wangli 已提交
592
setAssociatedData(name: string, key: string, value: string): Promise&lt;void&gt;
A
annie_wangli 已提交
593

A
annie_wangli 已提交
594
Sets data to be associated with an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
595

A
annie_wangli 已提交
596 597 598
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
599

A
annie_wangli 已提交
600 601 602 603 604
| Name  | Type    | Mandatory  | Description               |
| ----- | ------ | ---- | ----------------- |
| name  | string | Yes   | App account name.         |
| key   | string | Yes   | Key of the data to set. The private key can be customized.|
| value | string | Yes   | Value of the data to be set.        |
A
annie_wangli 已提交
605

A
annie_wangli 已提交
606
**Return Value**
A
annie_wangli 已提交
607

A
annie_wangli 已提交
608 609
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
annie_wangli 已提交
610
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
611

A
annie_wangli 已提交
612
**Example**
A
annie_wangli 已提交
613

Z
zhangalong 已提交
614
  ```js
A
annie_wangli 已提交
615 616 617 618 619 620 621 622 623 624
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { 
      console.log('setAssociatedData Success');
  }).catch((err) => {
      console.log("setAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### getAccountCredential

A
annie_wangli 已提交
625
getAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
626

A
annie_wangli 已提交
627
Obtains the credential of an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
628

A
annie_wangli 已提交
629
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
630

A
annie_wangli 已提交
631
**Parameters**
A
annie_wangli 已提交
632

A
annie_wangli 已提交
633 634 635 636 637
| Name           | Type                         | Mandatory  | Description            |
| -------------- | --------------------------- | ---- | -------------- |
| name           | string                      | Yes   | App account name.       |
| credentialType | string                      | Yes   | Type of the credential to obtain.    |
| callback       | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the credential of the specified app account.|
A
annie_wangli 已提交
638 639

**Example**
A
annie_wangli 已提交
640

Z
zhangalong 已提交
641
  ```js
A
annie_wangli 已提交
642 643 644 645 646 647 648 649 650
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { 
      console.log("getAccountCredential err: " + JSON.stringify(err));
      console.log('getAccountCredential result: ' + result);
  });
  ```

### getAccountCredential

A
annie_wangli 已提交
651
getAccountCredential(name: string, credentialType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
652

A
annie_wangli 已提交
653
Obtains the credential of an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
654

A
annie_wangli 已提交
655 656 657
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
658

A
annie_wangli 已提交
659 660 661 662
| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | App account name.   |
| credentialType | string | Yes   | Type of the credential to obtain.|
A
annie_wangli 已提交
663

A
annie_wangli 已提交
664
**Return Value**
A
annie_wangli 已提交
665

A
annie_wangli 已提交
666 667
| Type                   | Description                   |
| :-------------------- | :-------------------- |
A
annie_wangli 已提交
668
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
669

A
annie_wangli 已提交
670
**Example**
A
annie_wangli 已提交
671

Z
zhangalong 已提交
672
  ```js
A
annie_wangli 已提交
673 674 675 676 677 678 679 680 681 682
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { 
      console.log('getAccountCredential, result: ' + data);
  }).catch((err) => {
      console.log("getAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### getAccountExtraInfo

A
annie_wangli 已提交
683
getAccountExtraInfo(name: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
684

A
annie_wangli 已提交
685
Obtains additional information of an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
686

A
annie_wangli 已提交
687
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
688

A
annie_wangli 已提交
689
**Parameters**
A
annie_wangli 已提交
690

A
annie_wangli 已提交
691 692 693 694
| Name     | Type                         | Mandatory  | Description              |
| -------- | --------------------------- | ---- | ---------------- |
| name     | string                      | Yes   | App account name.         |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the additional information of the specified app account.|
A
annie_wangli 已提交
695 696

**Example**
A
annie_wangli 已提交
697

Z
zhangalong 已提交
698
  ```js
A
annie_wangli 已提交
699 700 701 702 703 704 705 706 707
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { 
      console.log("getAccountExtraInfo err: " + JSON.stringify(err));
      console.log('getAccountExtraInfo result: ' + result);
  });
  ```

### getAccountExtraInfo

A
annie_wangli 已提交
708
getAccountExtraInfo(name: string): Promise&lt;string&gt;
A
annie_wangli 已提交
709

A
annie_wangli 已提交
710
Obtains additional information of an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
711

A
annie_wangli 已提交
712 713 714
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
715

A
annie_wangli 已提交
716 717 718
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | App account name.|
A
annie_wangli 已提交
719

A
annie_wangli 已提交
720
**Return Value**
A
annie_wangli 已提交
721

A
annie_wangli 已提交
722 723
| Type                   | Description                   |
| :-------------------- | :-------------------- |
A
annie_wangli 已提交
724
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
725

A
annie_wangli 已提交
726
**Example**
A
annie_wangli 已提交
727

Z
zhangalong 已提交
728
  ```js
A
annie_wangli 已提交
729 730 731 732 733 734 735 736 737 738
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { 
      console.log('getAccountExtraInfo, result: ' + data);
  }).catch((err) => {
      console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### getAssociatedData

A
annie_wangli 已提交
739
getAssociatedData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
740

A
annie_wangli 已提交
741
Obtains data associated with an app account. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
742

A
annie_wangli 已提交
743
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
744

A
annie_wangli 已提交
745
**Parameters**
A
annie_wangli 已提交
746

A
annie_wangli 已提交
747 748 749 750 751
| Name     | Type                         | Mandatory  | Description               |
| -------- | --------------------------- | ---- | ----------------- |
| name     | string                      | Yes   | App account name.          |
| key      | string                      | Yes   | Key of the data to obtain.      |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the data associated with the specified app account.|
A
annie_wangli 已提交
752 753

**Example**
A
annie_wangli 已提交
754

Z
zhangalong 已提交
755
  ```js
A
annie_wangli 已提交
756 757 758 759 760 761 762 763 764
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { 
      console.log("getAssociatedData err: " + JSON.stringify(err));
      console.log('getAssociatedData result: ' + result);
  });
  ```

### getAssociatedData

A
annie_wangli 已提交
765
getAssociatedData(name: string, key: string): Promise&lt;string&gt;
A
annie_wangli 已提交
766

A
annie_wangli 已提交
767
Obtains data associated with an app account. This method uses a promise to return the result asynchronously.
A
annie_wangli 已提交
768

A
annie_wangli 已提交
769 770 771
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
772

A
annie_wangli 已提交
773 774 775 776
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| name | string | Yes   | App account name.    |
| key  | string | Yes   | Key of the data to obtain.|
A
annie_wangli 已提交
777

A
annie_wangli 已提交
778
**Return Value**
A
annie_wangli 已提交
779

A
annie_wangli 已提交
780 781
| Type                   | Description                   |
| :-------------------- | :-------------------- |
A
annie_wangli 已提交
782
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
783

A
annie_wangli 已提交
784
**Example**
A
annie_wangli 已提交
785

Z
zhangalong 已提交
786
  ```js
A
annie_wangli 已提交
787 788 789 790 791 792 793 794 795 796
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { 
       console.log('getAssociatedData: ' + data);
  }).catch((err) => {
      console.log("getAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### getAllAccessibleAccounts

A
annie_wangli 已提交
797
getAllAccessibleAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
798

A
annie_wangli 已提交
799
Obtains information about all accessible app accounts. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
800

A
annie_wangli 已提交
801
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
802

A
annie_wangli 已提交
803
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
804

A
annie_wangli 已提交
805
**Parameters**
A
annie_wangli 已提交
806

A
annie_wangli 已提交
807 808 809
| Name     | Type                                      | Mandatory  | Description      |
| -------- | ---------------------------------------- | ---- | -------- |
| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
A
annie_wangli 已提交
810 811

**Example**
A
annie_wangli 已提交
812

Z
zhangalong 已提交
813
  ```js
A
annie_wangli 已提交
814 815 816 817 818 819 820 821 822
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllAccessibleAccounts((err, data)=>{
  	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
  	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
  });
  ```

### getAllAccessibleAccounts

A
annie_wangli 已提交
823 824 825
getAllAccessibleAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Obtains information about all accessible app accounts. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
826

A
annie_wangli 已提交
827
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
828

A
annie_wangli 已提交
829
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
830

A
annie_wangli 已提交
831
**Parameters**
A
annie_wangli 已提交
832

A
annie_wangli 已提交
833 834
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
annie_wangli 已提交
835
| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
836

A
annie_wangli 已提交
837
**Example**
A
annie_wangli 已提交
838

Z
zhangalong 已提交
839
  ```js
A
annie_wangli 已提交
840 841 842 843 844 845 846 847 848 849
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllAccessibleAccounts().then((data) => { 
       console.log('getAllAccessibleAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
  });
  ```

### getAllAccounts

A
annie_wangli 已提交
850
getAllAccounts(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
851

A
annie_wangli 已提交
852
Obtains information about all app accounts of the specified app. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
853

A
annie_wangli 已提交
854
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
855 856

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
857

A
annie_wangli 已提交
858
**Parameters**
A
annie_wangli 已提交
859

A
annie_wangli 已提交
860 861 862 863
| Name     | Type                                      | Mandatory  | Description      |
| -------- | ---------------------------------------- | ---- | -------- |
| owner    | string                                   | Yes   | Bundle name of the app.   |
| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
A
annie_wangli 已提交
864

A
annie_wangli 已提交
865
**Example**
A
annie_wangli 已提交
866

Z
zhangalong 已提交
867
  ```js
A
annie_wangli 已提交
868 869 870 871 872 873 874 875 876 877
  const appAccountManager = account.createAppAccountManager();
  const selfBundle = "com.example.actsgetallaaccounts";
  appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
  	console.debug("getAllAccounts err:" + JSON.stringify(err));
  	console.debug("getAllAccounts data:" + JSON.stringify(data));
  });
  ```

### getAllAccounts

A
annie_wangli 已提交
878 879 880
getAllAccounts(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Obtains information about all app accounts of the specified app. This method uses an asynchronous callback to return the result.
A
annie_wangli 已提交
881

A
annie_wangli 已提交
882
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
883

A
annie_wangli 已提交
884
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
885

A
annie_wangli 已提交
886
**Parameters**
A
annie_wangli 已提交
887

A
annie_wangli 已提交
888 889 890
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| owner | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
891

A
annie_wangli 已提交
892
**Parameters**
A
annie_wangli 已提交
893

A
annie_wangli 已提交
894 895
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
annie_wangli 已提交
896
| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
897

A
annie_wangli 已提交
898
**Example**
A
annie_wangli 已提交
899

Z
zhangalong 已提交
900
  ```js
A
annie_wangli 已提交
901 902 903 904 905 906 907 908 909 910 911
  const appAccountManager = account_appAccount.createAppAccountManager();
  const selfBundle = "com.example.actsgetallaaccounts";
  appAccountManager.getAllAccounts(selfBundle).then((data) => { 
       console.log('getAllAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccounts err: "  + JSON.stringify(err));
  });
  ```

### on('change')

A
annie_wangli 已提交
912
on(type: 'change', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
913 914 915

Subscribes to the account change event of the specified account owners. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
916
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
917

A
annie_wangli 已提交
918
**Parameters**
A
annie_wangli 已提交
919

A
annie_wangli 已提交
920 921 922 923 924
| Name     | Type                                      | Mandatory  | Description                            |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| type     | 'change'                                 | Yes   | Type of the event to subscribe to. The subscriber will receive a notification when the account owners update their accounts.|
| owners   | Array&lt;string&gt;                      | Yes   | Owners of the accounts.                     |
| callback | Callback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return the account change.          |
A
annie_wangli 已提交
925 926

**Example**
A
annie_wangli 已提交
927

Z
zhangalong 已提交
928
  ```js
A
annie_wangli 已提交
929 930 931 932 933 934 935 936 937 938 939 940 941 942
  const appAccountManager = account.createAppAccountManager();
  function changeOnCallback(data){
  	console.debug("receive change data:" + JSON.stringify(data));
  }
  try{
  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  }
  catch(err){
  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  }
  ```

### off('change')

A
annie_wangli 已提交
943
off(type: 'change', callback?: Callback<Array\<AppAccountInfo>>): void
A
annie_wangli 已提交
944 945 946

Unsubscribes from the account change event. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
947 948 949
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
950

A
annie_wangli 已提交
951 952 953 954
| Name     | Type                              | Mandatory  | Description          |
| -------- | -------------------------------- | ---- | ------------ |
| type     | 'change'                         | Yes   | Account change event to unsubscribe from.   |
| callback | Callback<Array\<AppAccountInfo>> | No   | Callback used to report the account change.|
A
annie_wangli 已提交
955

A
annie_wangli 已提交
956
**Example**
A
annie_wangli 已提交
957

Z
zhangalong 已提交
958
  ```js
A
annie_wangli 已提交
959 960 961 962 963
  const appAccountManager = account.createAppAccountManager();
  function changeOnCallback(data){
  	console.debug("receive change data:" + JSON.stringify(data));
  	appAccountManager.off('change', function(){
  		console.debug("off finish");
A
annie_wangli 已提交
964
  	})
A
annie_wangli 已提交
965 966 967 968 969 970 971 972 973
  }
  try{
  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  }
  catch(err){
  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  }
  ```

A
annie_wangli 已提交
974 975
### authenticate<sup>8+</sup>

A
annie_wangli 已提交
976
authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
977 978 979

Authenticates an app account to obtain the Open Authorization (OAuth) access token. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
980 981 982
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
983

A
annie_wangli 已提交
984 985 986 987 988 989 990
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
| name     | string                | Yes   | Name of the app account to authenticate.   |
| owner    | string                | Yes   | Bundle name of the app.|
| authType | string                | Yes   | Authentication type.          |
| options  | {[key: string]: any}  | Yes   | Options for the authentication.      |
| callback | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
991

A
annie_wangli 已提交
992
**Example**
A
annie_wangli 已提交
993

Z
zhangalong 已提交
994
  ```js
A
annie_wangli 已提交
995
  import featureAbility from '@ohos.ability.featureAbility';
A
annie_wangli 已提交
996

A
annie_wangli 已提交
997 998 999 1000
  function onResultCallback(code, result) {
      console.log("resultCode: "  + code);
      console.log("result: "  + JSON.stringify(result));
  }
A
annie_wangli 已提交
1001

A
annie_wangli 已提交
1002 1003 1004 1005 1006 1007
  function onRequestRedirectedCallback(request) {
      let abilityStartSetting = {want: request};
      featureAbility.startAbility(abilityStartSetting, (err)=>{
          console.log("startAbility err: " + JSON.stringify(err));
      });
  }
A
annie_wangli 已提交
1008

A
annie_wangli 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "readAge", {}, {
    onResult: onResultCallback,
    onRequestRedirected: onRequestRedirectedCallback
  });
  ```

### getOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1018
getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1019 1020 1021

Obtains the OAuth access token of an app account based on the specified authentication type. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1022 1023 1024
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1025

A
annie_wangli 已提交
1026 1027 1028 1029 1030 1031
| Name     | Type                         | Mandatory  | Description         |
| -------- | --------------------------- | ---- | ----------- |
| name     | string                      | Yes   | App account name.   |
| owner    | string                      | Yes   | Bundle name of the app.|
| authType | string                      | Yes   | Authentication type.      |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1032

A
annie_wangli 已提交
1033
**Example**
A
annie_wangli 已提交
1034

Z
zhangalong 已提交
1035
  ```js
A
annie_wangli 已提交
1036 1037 1038 1039 1040 1041 1042 1043 1044
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", (err, data) => {
       console.log('getOAuthToken err: ' + JSON.stringify(err));
       console.log('getOAuthToken token: ' + data);
  });
  ```

### getOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1045
getOAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1046 1047 1048

Obtains the OAuth access token of an app account based on the specified authentication type. This method uses a promise to return the result.

A
annie_wangli 已提交
1049
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1050

A
annie_wangli 已提交
1051
**Parameters**
A
annie_wangli 已提交
1052

A
annie_wangli 已提交
1053 1054 1055 1056 1057
| Name     | Type    | Mandatory  | Description         |
| -------- | ------ | ---- | ----------- |
| name     | string | Yes   | App account name.   |
| owner    | string | Yes   | Bundle name of the app.|
| authType | string | Yes   | Authentication type.      |
A
annie_wangli 已提交
1058

A
annie_wangli 已提交
1059
**Parameters**
A
annie_wangli 已提交
1060

A
annie_wangli 已提交
1061 1062
| Type                   | Description                   |
| --------------------- | --------------------- |
A
annie_wangli 已提交
1063 1064 1065
| Promise&lt;string&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
1066

Z
zhangalong 已提交
1067
  ```js
A
annie_wangli 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge").then((data) => {
       console.log('getOAuthToken token: ' + data);
  }).catch((err) => {
      console.log("getOAuthToken err: "  + JSON.stringify(err));
  });
  ```

### setOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1078
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1079 1080 1081

Sets an OAuth access token for an app account. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1082 1083 1084
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1085

A
annie_wangli 已提交
1086 1087 1088 1089 1090 1091
| Name     | Type                       | Mandatory  | Description      |
| -------- | ------------------------- | ---- | -------- |
| name     | string                    | Yes   | App account name.|
| authType | string                    | Yes   | Authentication type.   |
| token    | string                    | Yes   | OAuth access token to set.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.|
A
annie_wangli 已提交
1092

A
annie_wangli 已提交
1093
**Example**
A
annie_wangli 已提交
1094

Z
zhangalong 已提交
1095
  ```js
A
annie_wangli 已提交
1096 1097 1098 1099 1100 1101 1102 1103
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx", (err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### setOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1104
setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1105 1106 1107

Sets an OAuth access token for an app account. This method uses a promise to return the result.

A
annie_wangli 已提交
1108
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1109

A
annie_wangli 已提交
1110
**Parameters**
A
annie_wangli 已提交
1111

A
annie_wangli 已提交
1112 1113 1114 1115 1116
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| name     | string | Yes   | App account name.|
| authType | string | Yes   | Authentication type.   |
| token    | string | Yes   | OAuth access token to set.|
A
annie_wangli 已提交
1117

A
annie_wangli 已提交
1118
**Parameters**
A
annie_wangli 已提交
1119

A
annie_wangli 已提交
1120 1121
| Type                 | Description                   |
| ------------------- | --------------------- |
A
annie_wangli 已提交
1122 1123 1124
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
1125

Z
zhangalong 已提交
1126
  ```js
A
annie_wangli 已提交
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx").then(() => {
      console.log('setOAuthToken successfully');
  }).catch((err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### deleteOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1137
deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1138 1139 1140

Deletes the specified OAuth access token for an app account. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1141 1142 1143
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1144

A
annie_wangli 已提交
1145 1146 1147 1148 1149 1150 1151
| Name     | Type                       | Mandatory  | Description          |
| -------- | ------------------------- | ---- | ------------ |
| name     | string                    | Yes   | App account name.    |
| owner    | string                    | Yes   | Bundle name of the app. |
| authType | string                    | Yes   | Authentication type.       |
| token    | string                    | Yes   | OAuth access token to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.    |
A
annie_wangli 已提交
1152

A
annie_wangli 已提交
1153
**Example**
A
annie_wangli 已提交
1154

Z
zhangalong 已提交
1155
  ```js
A
annie_wangli 已提交
1156 1157 1158 1159 1160 1161 1162 1163
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx", (err) => {
       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### deleteOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1164
deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1165 1166 1167

Deletes the specified OAuth access token for an app account. This method uses a promise to return the result.

A
annie_wangli 已提交
1168 1169 1170
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1171

A
annie_wangli 已提交
1172 1173 1174 1175 1176 1177
| Name     | Type    | Mandatory  | Description          |
| -------- | ------ | ---- | ------------ |
| name     | string | Yes   | App account name.    |
| owner    | string | Yes   | Bundle name of the app. |
| authType | string | Yes   | Authentication type.       |
| token    | string | Yes   | OAuth access token to delete.|
A
annie_wangli 已提交
1178

A
annie_wangli 已提交
1179
**Parameters**
A
annie_wangli 已提交
1180

A
annie_wangli 已提交
1181 1182
| Type                 | Description                   |
| ------------------- | --------------------- |
A
annie_wangli 已提交
1183
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1184

A
annie_wangli 已提交
1185
**Example**
A
annie_wangli 已提交
1186

Z
zhangalong 已提交
1187
  ```js
A
annie_wangli 已提交
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx").then(() => {
       console.log('deleteOAuthToken successfully');
  }).catch((err) => {
      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
  });
  ```

### setOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1198
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1199 1200 1201

Sets the visibility of an OAuth access token to the specified app. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1202
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1203

A
annie_wangli 已提交
1204
**Parameters**
A
annie_wangli 已提交
1205

A
annie_wangli 已提交
1206 1207 1208 1209 1210 1211 1212
| Name       | Type                       | Mandatory  | Description          |
| ---------- | ------------------------- | ---- | ------------ |
| name       | string                    | Yes   | App account name.    |
| authType   | string                    | Yes   | Authentication type.       |
| bundleName | string                    | Yes   | Bundle name of the app.|
| isVisible  | boolean                   | Yes   | Whether the OAuth access token is visible to the app.       |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.    |
A
annie_wangli 已提交
1213 1214

**Example**
A
annie_wangli 已提交
1215

Z
zhangalong 已提交
1216
  ```js
A
annie_wangli 已提交
1217 1218 1219 1220 1221 1222 1223 1224
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err) => {
       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### setOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1225
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
1226 1227 1228

Sets the visibility of an OAuth access token to the specified app. This method uses a promise to return the result.

A
annie_wangli 已提交
1229 1230 1231
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1232

A
annie_wangli 已提交
1233 1234 1235 1236 1237 1238
| Name       | Type     | Mandatory  | Description          |
| ---------- | ------- | ---- | ------------ |
| name       | string  | Yes   | App account name.    |
| authType   | string  | Yes   | Authentication type.       |
| bundleName | string  | Yes   | Bundle name of the app.|
| isVisible  | boolean | Yes   | Whether the OAuth access token is visible to the app.       |
A
annie_wangli 已提交
1239

A
annie_wangli 已提交
1240
**Parameters**
A
annie_wangli 已提交
1241

A
annie_wangli 已提交
1242 1243
| Type                 | Description                   |
| ------------------- | --------------------- |
A
annie_wangli 已提交
1244
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1245

A
annie_wangli 已提交
1246
**Example**
A
annie_wangli 已提交
1247

Z
zhangalong 已提交
1248
  ```js
A
annie_wangli 已提交
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then(() => {
      console.log('setOAuthTokenVisibility successfully');
  }).catch((err) => {
      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### checkOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1259
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
1260 1261 1262

Checks whether an OAuth token is visible to the specified app. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1263
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1264

A
annie_wangli 已提交
1265
**Parameters**
A
annie_wangli 已提交
1266

A
annie_wangli 已提交
1267 1268 1269 1270 1271 1272
| Name       | Type                          | Mandatory  | Description           |
| ---------- | ---------------------------- | ---- | ------------- |
| name       | string                       | Yes   | App account name.     |
| authType   | string                       | Yes   | Authentication type.        |
| bundleName | string                       | Yes   | Bundle name of the app.|
| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result.     |
A
annie_wangli 已提交
1273 1274

**Example**
A
annie_wangli 已提交
1275

Z
zhangalong 已提交
1276
  ```js
A
annie_wangli 已提交
1277 1278 1279 1280 1281 1282 1283 1284 1285
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err, data) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
  });
  ```

### checkOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1286
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
1287 1288 1289

Checks whether an OAuth token is visible to the specified app. This method uses a promise to return the result.

A
annie_wangli 已提交
1290 1291 1292
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1293

A
annie_wangli 已提交
1294 1295 1296 1297 1298
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
| name       | string | Yes   | App account name.     |
| authType   | string | Yes   | Authentication type.        |
| bundleName | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1299

A
annie_wangli 已提交
1300
**Parameters**
A
annie_wangli 已提交
1301

A
annie_wangli 已提交
1302 1303
| Type                    | Description                   |
| ---------------------- | --------------------- |
A
annie_wangli 已提交
1304
| Promise&lt;boolean&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1305

A
annie_wangli 已提交
1306
**Example**
A
annie_wangli 已提交
1307

Z
zhangalong 已提交
1308
  ```js
A
annie_wangli 已提交
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then((data) => {
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
  }).catch((err) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### getAllOAuthTokens<sup>8+</sup>

A
annie_wangli 已提交
1319
getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt;): void
A
annie_wangli 已提交
1320 1321 1322

Obtains information about all OAuth access tokens of an app account visible to the specified app. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1323
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1324

A
annie_wangli 已提交
1325
**Parameters**
A
annie_wangli 已提交
1326

A
annie_wangli 已提交
1327 1328 1329 1330 1331
| Name     | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| name     | string                                   | Yes   | App account name.   |
| owner    | string                                   | Yes   | Bundle name of the app.|
| callback | AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1332 1333

**Example**
A
annie_wangli 已提交
1334

Z
zhangalong 已提交
1335
  ```js
A
annie_wangli 已提交
1336 1337 1338 1339 1340 1341 1342 1343 1344
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => {
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  });
  ```

### getAllOAuthTokens<sup>8+</sup>

A
annie_wangli 已提交
1345
getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
A
annie_wangli 已提交
1346 1347 1348

Obtains information about all OAuth access tokens of an app account visible to the specified app. This method uses a promise to return the result.

A
annie_wangli 已提交
1349 1350 1351
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1352

A
annie_wangli 已提交
1353 1354 1355 1356
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| name  | string | Yes   | App account name.   |
| owner | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1357

A
annie_wangli 已提交
1358
**Parameters**
A
annie_wangli 已提交
1359

A
annie_wangli 已提交
1360 1361
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
annie_wangli 已提交
1362
| Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1363

A
annie_wangli 已提交
1364
**Example**
A
annie_wangli 已提交
1365

Z
zhangalong 已提交
1366
  ```js
A
annie_wangli 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => {
       console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
  });
  ```

### getOAuthList<sup>8+</sup>

A
annie_wangli 已提交
1377
getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1378 1379 1380

Obtains the authorization list of OAuth access tokens of an app account. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1381
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1382

A
annie_wangli 已提交
1383
**Parameters**
A
annie_wangli 已提交
1384

A
annie_wangli 已提交
1385 1386 1387 1388 1389
| Name     | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| name     | string                                   | Yes   | App account name.   |
| owner    | string                                   | Yes   | Bundle name of the app.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1390 1391

**Example**
A
annie_wangli 已提交
1392

Z
zhangalong 已提交
1393
  ```js
A
annie_wangli 已提交
1394 1395 1396 1397 1398 1399 1400 1401 1402
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge", (err, data) => {
       console.log('getOAuthList err: ' + JSON.stringify(err));
       console.log('getOAuthList data: ' + JSON.stringify(data));
  });
  ```

### getOAuthList<sup>8+</sup>

A
annie_wangli 已提交
1403
getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
A
annie_wangli 已提交
1404 1405 1406

Obtains the authorization list of OAuth access tokens of an app account. This method uses a promise to return the result.

A
annie_wangli 已提交
1407 1408 1409
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1410

A
annie_wangli 已提交
1411 1412 1413 1414
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| name  | string | Yes   | App account name.   |
| owner | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1415

A
annie_wangli 已提交
1416
**Parameters**
A
annie_wangli 已提交
1417

A
annie_wangli 已提交
1418 1419
| Type                                | Description                   |
| ---------------------------------- | --------------------- |
A
annie_wangli 已提交
1420
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1421

A
annie_wangli 已提交
1422
**Example**
A
annie_wangli 已提交
1423

Z
zhangalong 已提交
1424
  ```js
A
annie_wangli 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge").then((data) => {
       console.log('getOAuthList data: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getOAuthList err: "  + JSON.stringify(err));
  });
  ```

### getAuthenticatorCallback<sup>8+</sup>

A
annie_wangli 已提交
1435
getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
A
annie_wangli 已提交
1436 1437 1438

Obtains the authenticator callback for a session. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1439 1440 1441
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1442

A
annie_wangli 已提交
1443 1444 1445 1446
| Name      | Type                                      | Mandatory  | Description      |
| --------- | ---------------------------------------- | ---- | -------- |
| sessionId | string                                   | Yes   | ID of the session to authenticate.|
| callback  | AsyncCallback&lt;AuthenticatorCallback&gt; | Yes   | Callback invoked to return the result.|
A
annie_wangli 已提交
1447

A
annie_wangli 已提交
1448
**Example**
A
annie_wangli 已提交
1449

Z
zhangalong 已提交
1450
  ```js
A
annie_wangli 已提交
1451 1452
  const appAccountManager = account_appAccount.createAppAccountManager();
  featureAbility.getWant((err, want) => {
A
annie_wangli 已提交
1453
    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
A
annie_wangli 已提交
1454
    appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
A
annie_wangli 已提交
1455
        if (err.code != account_appAccount.ResultCode.SUCCESS) {
A
annie_wangli 已提交
1456 1457 1458
            console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
            return;
        }
A
annie_wangli 已提交
1459 1460 1461 1462 1463
        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                      [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1464 1465 1466 1467 1468 1469
    });
  });
  ```

### getAuthenticatorCallback<sup>8+</sup>

A
annie_wangli 已提交
1470
getAuthenticatorCallback(sessionId: string): Promise&lt;AuthenticatorCallback&gt;
A
annie_wangli 已提交
1471 1472 1473

Obtains the authenticator callback for a session. This method uses a promise to return the result.

A
annie_wangli 已提交
1474
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1475

A
annie_wangli 已提交
1476
**Parameters**
A
annie_wangli 已提交
1477

A
annie_wangli 已提交
1478 1479 1480
| Name      | Type    | Mandatory  | Description      |
| --------- | ------ | ---- | -------- |
| sessionId | string | Yes   | ID of the session to authenticate.|
A
annie_wangli 已提交
1481

A
annie_wangli 已提交
1482
**Parameters**
A
annie_wangli 已提交
1483

A
annie_wangli 已提交
1484 1485
| Type                                  | Description                   |
| ------------------------------------ | --------------------- |
A
annie_wangli 已提交
1486 1487 1488
| Promise&lt;AuthenticatorCallback&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
1489

Z
zhangalong 已提交
1490
  ```js
A
annie_wangli 已提交
1491 1492
  const appAccountManager = account_appAccount.createAppAccountManager();
  featureAbility.getWant().then((want) => {
A
annie_wangli 已提交
1493
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
A
annie_wangli 已提交
1494
      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
1495 1496 1497 1498 1499
          var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                        [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
      }).catch((err) => {
          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
      });
  }).catch((err) => {
      console.log("getWant err: "  + JSON.stringify(err));
  });
  ```

### getAuthenticatorInfo<sup>8+</sup>

A
annie_wangli 已提交
1510
getAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void
A
annie_wangli 已提交
1511 1512 1513

Obtains authenticator information of an app account. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1514 1515 1516
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1517

A
annie_wangli 已提交
1518 1519 1520 1521
| Name     | Type                                    | Mandatory  | Description         |
| -------- | -------------------------------------- | ---- | ----------- |
| owner    | string                                 | Yes   | Bundle name of the app.|
| callback | AsyncCallback&lt;AuthenticatorInfo&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1522

A
annie_wangli 已提交
1523
**Example**
A
annie_wangli 已提交
1524

Z
zhangalong 已提交
1525
  ```js
A
annie_wangli 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
      console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
  });
  ```

### getAuthenticatorInfo<sup>8+</sup>

A
annie_wangli 已提交
1535
getAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;
A
annie_wangli 已提交
1536 1537 1538

Obtains authenticator information of an app account. This method uses a promise to return the result.

A
annie_wangli 已提交
1539
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1540

A
annie_wangli 已提交
1541
**Parameters**
A
annie_wangli 已提交
1542

A
annie_wangli 已提交
1543 1544 1545
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1546

A
annie_wangli 已提交
1547
**Parameters**
A
annie_wangli 已提交
1548

A
annie_wangli 已提交
1549 1550
| Type                              | Description                   |
| -------------------------------- | --------------------- |
A
annie_wangli 已提交
1551 1552 1553
| Promise&lt;AuthenticatorInfo&gt; | Promise used to return the result.|

**Example**
A
annie_wangli 已提交
1554

Z
zhangalong 已提交
1555
  ```js
A
annie_wangli 已提交
1556 1557 1558 1559 1560 1561 1562 1563
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => { 
       console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
1564 1565
## AppAccountInfo

A
annie_wangli 已提交
1566 1567
Defines app account information.

A
annie_wangli 已提交
1568 1569
**System capability**: SystemCapability.Account.AppAccount

A
annie_wangli 已提交
1570 1571 1572 1573
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Bundle name of the app.|
| name  | string | Yes   | App account name.   |
A
annie_wangli 已提交
1574 1575

## OAuthTokenInfo<sup>8+</sup>
A
annie_wangli 已提交
1576

A
annie_wangli 已提交
1577
Defines OAuth access token information.
A
annie_wangli 已提交
1578

A
annie_wangli 已提交
1579 1580
**System capability**: SystemCapability.Account.AppAccount

A
annie_wangli 已提交
1581 1582 1583 1584
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| authType | string | Yes   | Authentication type.|
| token    | string | Yes   | Value of the access token.  |
A
annie_wangli 已提交
1585 1586 1587 1588 1589

## AuthenticatorInfo<sup>8+</sup>

Defines OAuth authenticator information.

A
annie_wangli 已提交
1590 1591
**System capability**: SystemCapability.Account.AppAccount

A
annie_wangli 已提交
1592 1593 1594 1595 1596
| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| owner   | string | Yes   | Bundle name of the authenticator owner.|
| iconId  | string | Yes   | ID of the authenticator icon. |
| labelId | string | Yes   | ID of the authenticator label. |
A
annie_wangli 已提交
1597 1598 1599 1600 1601

## Constants<sup>8+</sup>

Enumerates the constants.

A
annie_wangli 已提交
1602 1603
**System capability**: SystemCapability.Account.AppAccount

A
annie_wangli 已提交
1604 1605 1606 1607 1608
| Name                           | Default Value                   | Description           |
| ----------------------------- | ---------------------- | ------------- |
| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation for implicitly adding an account. |
| ACTION_AUTHENTICATE           | "authenticate"         | Authentication operation.     |
| KEY_NAME                      | "name"                 | App account name. |
A
annie_wangli 已提交
1609
| KEY_OWNER                     | "owner"                | App account owner.|
A
annie_wangli 已提交
1610 1611 1612 1613 1614 1615 1616
| KEY_TOKEN                     | "token"                | OAuth access token.     |
| KEY_ACTION                    | "action"               | Action.     |
| KEY_AUTH_TYPE                 | "authType"             | Authentication type.   |
| KEY_SESSION_ID                | "sessionId"            | Session ID.   |
| KEY_CALLER_PID                | "callerPid"            | Caller process ID (PID). |
| KEY_CALLER_UID                | "callerUid"            | Caller user ID (UID). |
| KEY_CALLER_BUNDLE_NAME        | "callerBundleName"     | Caller bundle name.  |
A
annie_wangli 已提交
1617 1618 1619 1620 1621

## ResultCode<sup>8+</sup>

Enumerates the result codes.

A
annie_wangli 已提交
1622 1623
**System capability**: SystemCapability.Account.AppAccount

A
annie_wangli 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
| Name                                 | Default Value  | Description          |
| ----------------------------------- | ----- | ------------ |
| SUCCESS                             | 0     | The operation is successful.     |
| ERROR_ACCOUNT_NOT_EXIST             | 10001 | The app account does not exist.  |
| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The app account service is abnormal. |
| ERROR_INVALID_PASSWORD              | 10003 | The password is invalid.     |
| ERROR_INVALID_REQUEST               | 10004 | The request is invalid.     |
| ERROR_INVALID_RESPONSE              | 10005 | The response is invalid.     |
| ERROR_NETWORK_EXCEPTION             | 10006 | The network is abnormal.     |
| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist.   |
| ERROR_OAUTH_CANCELED                | 10008 | The authentication is canceled.     |
| ERROR_OAUTH_LIST_TOO_LARGE          | 10009 | The size of the OAuth list exceeds the limit. |
| ERROR_OAUTH_SERVICE_BUSY            | 10010 | The OAuth service is busy. |
| ERROR_OAUTH_SERVICE_EXCEPTION       | 10011 | The OAuth service is abnormal. |
| ERROR_OAUTH_SESSION_NOT_EXIST       | 10012 | The session to be authenticated does not exist.  |
| ERROR_OAUTH_TIMEOUT                 | 10013 | The authentication timed out.     |
| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | The OAuth access token does not exist.|
| ERROR_OAUTH_TOKEN_TOO_MANY          | 10015 | The number of OAuth access tokens reaches the limit. |
| ERROR_OAUTH_UNSUPPORT_ACTION        | 10016 | The authentication operation is not supported. |
| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE     | 10017 | The authentication type is not supported. |
| ERROR_PERMISSION_DENIED             | 10018 | The required permission is missing.     |
A
annie_wangli 已提交
1645 1646 1647 1648 1649 1650 1651

## AuthenticatorCallback<sup>8+</sup>

Provides methods for managing the OAuth authenticator callback.

### onResult<sup>8+</sup>

A
annie_wangli 已提交
1652
onResult: (code: number, result: {[key: string]: any}) =&gt; void
A
annie_wangli 已提交
1653 1654 1655

Called back to send the authentication result.

A
annie_wangli 已提交
1656 1657 1658
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1659 1660 1661 1662
| Name   | Type                  | Mandatory  | Description    |
| ------ | -------------------- | ---- | ------ |
| code   | number               | Yes   | Authentication result code.|
| result | {[key: string]: any} | Yes   | Authentication result. |
A
annie_wangli 已提交
1663

A
annie_wangli 已提交
1664
**Example**
A
annie_wangli 已提交
1665

Z
zhangalong 已提交
1666
  ```js
A
annie_wangli 已提交
1667 1668 1669
  const appAccountManager = account_appAccount.createAppAccountManager();
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
1670 1671 1672 1673 1674
      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                    [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
      callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1675 1676 1677 1678 1679 1680 1681
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

### onRequestRedirected<sup>8+</sup>

A
annie_wangli 已提交
1682
onRequestRedirected: (request: Want) =&gt; void
A
annie_wangli 已提交
1683 1684 1685

Called back to redirect an authentication request.

A
annie_wangli 已提交
1686
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1687

A
annie_wangli 已提交
1688
**Parameters**
A
annie_wangli 已提交
1689 1690 1691
| Name    | Type  | Mandatory  | Description        |
| ------- | ---- | ---- | ---------- |
| request | Want | Yes   | Request to be redirected.|
A
annie_wangli 已提交
1692 1693

**Example**
A
annie_wangli 已提交
1694

Z
zhangalong 已提交
1695
  ```js
A
annie_wangli 已提交
1696 1697 1698 1699 1700 1701 1702
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
              bundleName: "com.example.ohos.accountjsdemo",
              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
          });
      }
A
annie_wangli 已提交
1703

A
annie_wangli 已提交
1704
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
1705 1706 1707 1708
          var result = {[account_appAccount.Constants.KEY_NAME]: name,
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
      }
  }
  ```

## Authenticator<sup>8+</sup>

Defines the OAuth authenticator base class.

### addAccountImplicitly<sup>8+</sup>

A
annie_wangli 已提交
1719
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
1720 1721 1722

Implicitly adds an app account based on the specified authentication type and options. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1723 1724 1725
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1726 1727 1728 1729 1730 1731
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| authType         | string                | Yes   | Authentication type.     |
| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
| callback         | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
1732 1733 1734

### authenticate<sup>8+</sup>

A
annie_wangli 已提交
1735
authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
1736 1737 1738

Authenticates an app account to obtain the OAuth access token. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1739 1740 1741
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1742 1743 1744 1745 1746 1747 1748
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| name             | string                | Yes   | App account name.       |
| authType         | string                | Yes   | Authentication type.     |
| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
| callback         | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
1749

A
annie_wangli 已提交
1750
**Example**
A
annie_wangli 已提交
1751

Z
zhangalong 已提交
1752
  ```js
A
annie_wangli 已提交
1753 1754 1755 1756 1757 1758 1759
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
              bundleName: "com.example.ohos.accountjsdemo",
              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
          });
      }
A
annie_wangli 已提交
1760

A
annie_wangli 已提交
1761
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
1762 1763 1764 1765
          var result = {[account_appAccount.Constants.KEY_NAME]: name,
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1766 1767
      }
  }
A
annie_wangli 已提交
1768

A
annie_wangli 已提交
1769 1770 1771 1772 1773 1774
  export default {
      onConnect(want) {
          return new MyAuthenticator();
      }
  }
  ```