js-apis-appAccount.md 183.0 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.account.appAccount (App Account Management)
A
Annie_wang 已提交
2

A
Annie_wang 已提交
3
The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app authentication and distributed data synchronization.
A
annie_wangli 已提交
4

A
Annie_wang 已提交
5 6
> **NOTE**
> 
A
annie_wangli 已提交
7 8 9 10 11
> 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 已提交
12
```js
A
annie_wangli 已提交
13 14 15 16 17 18
import account_appAccount from '@ohos.account.appAccount';
```


## account_appAccount.createAppAccountManager

A
annie_wangli 已提交
19
createAppAccountManager(): AppAccountManager
A
annie_wangli 已提交
20

A
Annie_wang 已提交
21
Creates an **AppAccountManager** object.
A
annie_wangli 已提交
22

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

A
Annie_wang 已提交
25
**Return value**
A
Annie_wang 已提交
26 27 28

| Type               | Description          |
| ----------------- | ------------ |
A
Annie_wang 已提交
29
| AppAccountManager | **AppAccountManager** object created.|
A
annie_wangli 已提交
30 31

**Example**
Z
zhangalong 已提交
32
  ```js
A
Annie_wang 已提交
33
  let appAccountManager = account_appAccount.createAppAccountManager();
A
annie_wangli 已提交
34 35 36 37
  ```

## AppAccountManager

A
Annie_wang 已提交
38
Implements app account management.
A
annie_wangli 已提交
39

A
Annie_wang 已提交
40
### createAccount<sup>9+</sup>
A
annie_wangli 已提交
41

A
Annie_wang 已提交
42
createAccount(name: string, callback: AsyncCallback&lt;void&gt;): void;
A
annie_wangli 已提交
43

A
Annie_wang 已提交
44
Creates an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
45

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

A
annie_wangli 已提交
48
**Parameters**
A
annie_wangli 已提交
49

A
Annie_wang 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62
| Name     | Type                   | Mandatory | Description              |
| -------- | ------------------------- | ----- | -------------------- |
| name     | string                    | Yes   | Name of the app account to create.         |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
A
annie_wangli 已提交
63

A
annie_wangli 已提交
64
**Example**
A
annie_wangli 已提交
65

Z
zhangalong 已提交
66
  ```js
A
Annie_wang 已提交
67 68 69 70 71 72 73
  try {
    appAccountManager.createAccount("WangWu", (err) => { 
        console.log("createAccount err: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("createAccount err: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
74 75
  ```

A
Annie_wang 已提交
76
### createAccount<sup>9+</sup>
A
annie_wangli 已提交
77

A
Annie_wang 已提交
78
createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
79

A
Annie_wang 已提交
80
Creates an app account with custom data. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
81

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

A
annie_wangli 已提交
84
**Parameters**
A
annie_wangli 已提交
85

A
Annie_wang 已提交
86 87
| Name      | Type                       | Mandatory  | Description                                      |
| --------- | ------------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
88 89 90 91 92 93 94 95 96 97 98 99
| name      | string                    | Yes   | Name of the app account to create.                             |
| options | [CreateAccountOptions](#createaccountoptions9) | Yes   | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens).|
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.            |

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or options. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
A
annie_wangli 已提交
100

A
annie_wangli 已提交
101
**Example**
A
annie_wangli 已提交
102

Z
zhangalong 已提交
103
  ```js
A
Annie_wang 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  let options = {
    customData: {
      "age": "10"
    }
  }
  try {
    appAccountManager.createAccount("LiSi", options, (err) => {
      if (err) {
        console.log("createAccount failed, error: " + JSON.stringify(err));
      } else {
        console.log("createAccount successfully");
      }
    });
  } catch(err) {
    console.log("createAccount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
120 121
  ```

A
Annie_wang 已提交
122
### createAccount<sup>9+</sup>
A
annie_wangli 已提交
123

A
Annie_wang 已提交
124
createAccount(name: string, options?: CreateAccountOptions): Promise&lt;void&gt;
A
annie_wangli 已提交
125

A
Annie_wang 已提交
126
Creates an app account with custom data. This API uses a promise to return the result.
A
annie_wangli 已提交
127

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

A
annie_wangli 已提交
130
**Parameters**
A
annie_wangli 已提交
131

A
Annie_wang 已提交
132 133
| Name      | Type    | Mandatory  | Description                                      |
| --------- | ------ | ---- | ---------------------------------------- |
A
Annie_wang 已提交
134 135
| name      | string | Yes   | Name of the app account to create.                             |
| options | [CreateAccountOptions](#createaccountoptions9) | No   | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens). This parameter can be left empty.|
A
annie_wangli 已提交
136

A
Annie_wang 已提交
137
**Return value**
A
annie_wangli 已提交
138

A
Annie_wang 已提交
139 140
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
141 142 143 144 145 146 147 148 149 150 151
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or options. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
| 12400003 | The number of custom data reaches the upper limit. |
A
annie_wangli 已提交
152

A
annie_wangli 已提交
153
**Example**
A
annie_wangli 已提交
154

Z
zhangalong 已提交
155
  ```js
A
Annie_wang 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169
  let options = {
    customData: {
      "age": "10"
    }
  }
  try {
    appAccountManager.createAccount("LiSi", options).then(() => {
      console.log("createAccount successfully");
    }).catch((err) => {
      console.log("createAccount failed, error: " + JSON.stringify(err));
    });
  } catch(err) {
    console.log("createAccount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
170 171
  ```

A
Annie_wang 已提交
172
### createAccountImplicitly<sup>9+</sup>
A
annie_wangli 已提交
173

A
Annie_wang 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
createAccountImplicitly(owner: string, callback: AuthCallback): void

Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type               | Mandatory  | Description                     |
| -------- | --------------------- | ---- | ----------------------- |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app.         |
| callback | [AuthCallback](#authcallback9) | Yes   | Authenticator callback used to return the result.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300007 | The number of accounts reaches the upper limit. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  function onResultCallback(code, result) {
    console.log("resultCode: "  + code);
    console.log("result: "  + JSON.stringify(result));
  }

  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
207 208 209 210 211 212 213 214 215
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
A
Annie_wang 已提交
216
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
217
    })
A
Annie_wang 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  }

  try {  
    appAccountManager.createAccountImplicitly("com.example.accountjsdemo", {
      onResult: onResultCallback,
      onRequestRedirected: onRequestRedirectedCallback
    });
  } catch (err) {
    console.log("createAccountImplicitly exception: " + JSON.stringify(err));
  }
  ```

### createAccountImplicitly<sup>9+</sup>

createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void

Creates an app account implicitly based on the specified account owner and options. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
235

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

A
annie_wangli 已提交
238
**Parameters**
A
annie_wangli 已提交
239

A
Annie_wang 已提交
240 241
| Name     | Type                   | Mandatory  | Description                     |
| -------- | --------------------- | ---- | ----------------------- |
A
Annie_wang 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app.         |
| options    | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9)   | Yes   | Options for implicitly creating the account.         |
| callback | [AuthCallback](#authcallback9) | Yes   | Authenticator callback used to return the result.        |

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or options. |
| 12300007 | The number of accounts reaches the upper limit. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
A
annie_wangli 已提交
256

A
annie_wangli 已提交
257
**Example**
A
annie_wangli 已提交
258

Z
zhangalong 已提交
259
  ```js
A
annie_wangli 已提交
260
  function onResultCallback(code, result) {
A
Annie_wang 已提交
261 262
    console.log("resultCode: "  + code);
    console.log("result: "  + JSON.stringify(result));
A
annie_wangli 已提交
263
  }
A
annie_wangli 已提交
264

A
annie_wangli 已提交
265
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
266 267 268 269 270 271 272 273 274
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
A
Annie_wang 已提交
275
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
276
    })
A
annie_wangli 已提交
277
  }
A
annie_wangli 已提交
278

A
Annie_wang 已提交
279 280 281 282 283 284
  let options = {
    authType: "getSocialData",
    requiredLabels: [ "student" ]
  };
  try {
    appAccountManager.createAccountImplicitly("com.example.accountjsdemo", options, {
A
annie_wangli 已提交
285 286
      onResult: onResultCallback,
      onRequestRedirected: onRequestRedirectedCallback
A
Annie_wang 已提交
287 288 289 290
    });
  } catch (err) {
    console.log("createAccountImplicitly exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
291 292
  ```

A
Annie_wang 已提交
293
### removeAccount<sup>9+</sup>
A
annie_wangli 已提交
294

A
Annie_wang 已提交
295
removeAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
296

A
Annie_wang 已提交
297
Removes an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
298

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

A
annie_wangli 已提交
301
**Parameters**
A
annie_wangli 已提交
302

A
Annie_wang 已提交
303 304
| Name     | Type                       | Mandatory  | Description              |
| -------- | ------------------------- | ---- | ---------------- |
A
Annie_wang 已提交
305 306 307 308 309 310 311 312 313 314
| name     | string                    | Yes   | Name of the app account to remove.     |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
315 316

**Example**
A
annie_wangli 已提交
317

Z
zhangalong 已提交
318
  ```js
A
Annie_wang 已提交
319 320 321 322 323 324 325
  try {
    appAccountManager.removeAccount("ZhaoLiu", (err) => {
      if (err) {
        console.log("removeAccount failed, error: " + JSON.stringify(err));
      } else {
        console.log("removeAccount successfully");
      }
A
annie_wangli 已提交
326
   });
A
Annie_wang 已提交
327 328 329
  } catch(err) {
    console.log("removeAccount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
330 331
  ```

A
Annie_wang 已提交
332
### removeAccount<sup>9+</sup>
A
annie_wangli 已提交
333

A
Annie_wang 已提交
334
removeAccount(name: string): Promise&lt;void&gt;
A
annie_wangli 已提交
335

A
Annie_wang 已提交
336
Removes an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
337

A
annie_wangli 已提交
338 339 340
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
341

A
Annie_wang 已提交
342 343
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
A
Annie_wang 已提交
344
| name | string | Yes   | Name of the app account to remove.|
A
annie_wangli 已提交
345

A
Annie_wang 已提交
346
**Return value**
A
annie_wangli 已提交
347

A
Annie_wang 已提交
348 349
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
350 351 352 353 354 355 356 357 358
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
359

A
annie_wangli 已提交
360
**Example**
A
annie_wangli 已提交
361

Z
zhangalong 已提交
362
  ```js
A
Annie_wang 已提交
363 364 365 366 367 368 369 370 371
  try {
    appAccountManager.removeAccount("Lisi").then(() => {
      console.log("removeAccount successfully");
    }).catch((err) => {
      console.log("removeAccount failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("removeAccount exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
372 373
  ```

A
Annie_wang 已提交
374
### setAppAccess<sup>9+</sup>
A
annie_wangli 已提交
375

A
Annie_wang 已提交
376
setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
377

A
Annie_wang 已提交
378
Sets the access to the data of an account for an app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
379

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

A
annie_wangli 已提交
382
**Parameters**
A
annie_wangli 已提交
383

A
Annie_wang 已提交
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
| Name       | Type                     | Mandatory  | Description                               |
| ------------ | ------------------------- | ---- | --------------------------------- |
| name         | string                    | Yes   | Name of the target app account.                          |
| bundleName   | string                    | Yes   | Bundle name of the app.                        |
| isAccessible | boolean                   | Yes   | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.|
| callback     | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
399 400

**Example**
A
annie_wangli 已提交
401

Z
zhangalong 已提交
402
  ```js
A
Annie_wang 已提交
403 404 405 406 407 408 409 410 411 412 413
  try {
    appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true, (err) => {
      if (err) {
        console.log("setAppAccess failed: " + JSON.stringify(err));
      } else {
        console.log("setAppAccess successfully");
      }
    });
  } catch (err) {
    console.log("setAppAccess exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
414 415
  ```

A
Annie_wang 已提交
416
### setAppAccess<sup>9+</sup>
A
annie_wangli 已提交
417

A
Annie_wang 已提交
418
setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
419

A
Annie_wang 已提交
420
Sets the access to the data of an account for an app. This API uses a promise to return the result.
A
annie_wangli 已提交
421

A
annie_wangli 已提交
422 423 424
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
425

A
Annie_wang 已提交
426 427 428 429 430
| Name       | Type    | Mandatory  | Description       |
| ---------- | ------ | ---- | --------- |
| name       | string | Yes   | Name of the target app account.  |
| bundleName | string | Yes   | Bundle name of the app.|
| isAccessible | boolean | Yes   | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.|
A
annie_wangli 已提交
431

A
Annie_wang 已提交
432
**Return value**
A
annie_wangli 已提交
433

A
Annie_wang 已提交
434 435
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
436 437 438 439 440 441 442 443 444 445
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
446

A
annie_wangli 已提交
447
**Example**
A
annie_wangli 已提交
448

Z
zhangalong 已提交
449
  ```js
A
Annie_wang 已提交
450 451 452 453 454 455 456 457 458
  try {
    appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true).then(() => {
      console.log("setAppAccess successfully");
    }).catch((err) => {
      console.log("setAppAccess failed: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("setAppAccess exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
459 460
  ```

A
Annie_wang 已提交
461
### checkAppAccess<sup>9+</sup>
A
annie_wangli 已提交
462

A
Annie_wang 已提交
463
checkAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
464

A
Annie_wang 已提交
465
Checks whether an app can access the data of an account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
466

A
annie_wangli 已提交
467 468 469
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
470

A
Annie_wang 已提交
471 472 473
| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                          |
A
Annie_wang 已提交
474
| bundleName | string                    | Yes   | Bundle name of the app.                        |
A
Annie_wang 已提交
475 476 477 478 479 480 481 482 483 484
| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
485

A
annie_wangli 已提交
486
**Example**
A
annie_wangli 已提交
487

Z
zhangalong 已提交
488
  ```js
A
Annie_wang 已提交
489 490 491 492 493 494 495 496 497 498 499
  try {
    appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo", (err, isAccessible) => {
      if (err) {
        console.log("checkAppAccess failed, error: " + JSON.stringify(err));
      } else {
        console.log("checkAppAccess successfully");
      }
    });
  } catch (err) {
    console.log("checkAppAccess exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
500 501
  ```

A
Annie_wang 已提交
502
### checkAppAccess<sup>9+</sup>
A
annie_wangli 已提交
503

A
Annie_wang 已提交
504
checkAppAccess(name: string, bundleName: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
505

A
Annie_wang 已提交
506
Checks whether an app can access the data of an account. This API uses a promise to return the result.
A
annie_wangli 已提交
507

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

A
annie_wangli 已提交
510
**Parameters**
A
annie_wangli 已提交
511

A
Annie_wang 已提交
512 513 514
| Name       | Type    | Mandatory  | Description       |
| ---------- | ------ | ---- | --------- |
| name       | string | Yes   | Name of the target app account.  |
A
Annie_wang 已提交
515
| bundleName | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
516

A
Annie_wang 已提交
517
**Return value**
A
annie_wangli 已提交
518

A
Annie_wang 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400001 | Application not found. |

**Example**

  ```js
  try {
    appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo").then((isAccessible) => {
      console.log("checkAppAccess successfully, isAccessible: " + isAccessible);
    }).catch((err) => {
      console.log("checkAppAccess failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("checkAppAccess exception: " + JSON.stringify(err));
  }
  ```

### setDataSyncEnabled<sup>9+</sup>

setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback&lt;void&gt;): void

Sets data synchronization for an app account. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                       | Mandatory  | Description                       |
| -------- | ------------------------- | ---- | ------------------------- |
| name     | string                    | Yes   | Name of the target app account.                  |
| isEnabled | boolean                   | Yes   | Whether to enable data synchronization.              |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |

**Example**

  ```js
  try {
      appAccountManager.setDataSyncEnabled("ZhangSan", true, (err) => { 
          console.log("setDataSyncEnabled err: " + JSON.stringify(err));
      });
  } catch (err) {
      console.log("setDataSyncEnabled err: " + JSON.stringify(err));
  }
  ```

### setDataSyncEnabled<sup>9+</sup>

setDataSyncEnabled(name: string, isEnabled: boolean): Promise&lt;void&gt;

Sets data synchronization for an app account. This API uses a promise to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type     | Mandatory  | Description         |
| -------- | ------- | ---- | ----------- |
| name     | string  | Yes   | Name of the target app account.    |
| isEnabled | boolean | Yes   | Whether to enable data synchronization.|

**Return value**

A
Annie_wang 已提交
603 604
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
605 606 607 608 609 610 611 612 613
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
614 615

**Example**
A
annie_wangli 已提交
616

Z
zhangalong 已提交
617
  ```js
A
Annie_wang 已提交
618 619 620 621 622 623 624 625 626
  try {
      appAccountManager .setDataSyncEnabled("ZhangSan", true).then(() => { 
          console.log('setDataSyncEnabled Success');
      }).catch((err) => {
          console.log("setDataSyncEnabled err: "  + JSON.stringify(err));
      });
  } catch (err) {
      console.log("setDataSyncEnabled err: "  + JSON.stringify(err));
  }
A
annie_wangli 已提交
627 628
  ```

A
Annie_wang 已提交
629
### checkDataSyncEnabled<sup>9+</sup>
A
annie_wangli 已提交
630

A
Annie_wang 已提交
631
checkDataSyncEnabled(name: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
632

A
Annie_wang 已提交
633
Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
634

A
Annie_wang 已提交
635
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
636 637

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

A
annie_wangli 已提交
639
**Parameters**
A
annie_wangli 已提交
640

A
Annie_wang 已提交
641 642 643
| Name     | Type                          | Mandatory  | Description                   |
| -------- | ---------------------------- | ---- | --------------------- |
| name     | string                       | Yes   | Name of the target app account.              |
A
Annie_wang 已提交
644 645 646 647 648 649 650 651 652
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
653

A
annie_wangli 已提交
654
**Example**
A
annie_wangli 已提交
655

Z
zhangalong 已提交
656
  ```js
A
Annie_wang 已提交
657 658 659 660 661 662 663 664 665 666 667
  try {
    appAccountManager.checkDataSyncEnabled("ZhangSan", (err, isEnabled) => {
      if (err) {
        console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
      } else {
        console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
      }
    });
  } catch (err) {
    console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
668 669
  ```

A
Annie_wang 已提交
670
### checkDataSyncEnabled<sup>9+</sup>
A
annie_wangli 已提交
671

A
Annie_wang 已提交
672
checkDataSyncEnabled(name: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
673

A
Annie_wang 已提交
674
Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
675

A
Annie_wang 已提交
676
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
677

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

A
annie_wangli 已提交
680
**Parameters**
A
annie_wangli 已提交
681

A
Annie_wang 已提交
682 683 684
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|
A
annie_wangli 已提交
685

A
Annie_wang 已提交
686
**Return value**
A
annie_wangli 已提交
687

A
Annie_wang 已提交
688 689
| Type                    | Description                   |
| :--------------------- | :-------------------- |
A
Annie_wang 已提交
690 691 692 693 694 695 696 697 698
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
699 700

**Example**
A
annie_wangli 已提交
701

Z
zhangalong 已提交
702
  ```js
A
Annie_wang 已提交
703 704 705 706 707 708 709 710 711
  try {
    appAccountManager.checkDataSyncEnabled("ZhangSan").then((isEnabled) => {
        console.log("checkDataSyncEnabled successfully, isEnabled: " + isEnabled);
    }).catch((err) => {
      console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("checkDataSyncEnabled err: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
712 713
  ```

A
Annie_wang 已提交
714
### setCredential<sup>9+</sup>
A
annie_wangli 已提交
715

A
Annie_wang 已提交
716
setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
717

A
Annie_wang 已提交
718
Sets a credential for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
719

A
annie_wangli 已提交
720 721 722
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
723

A
Annie_wang 已提交
724 725 726 727
| Name           | Type                       | Mandatory  | Description           |
| -------------- | ------------------------- | ---- | ------------- |
| name           | string                    | Yes   | Name of the target app account.    |
| credentialType | string                    | Yes   | Type of the credential to set.    |
A
Annie_wang 已提交
728 729 730 731 732 733 734 735 736 737
| credential     | string                    | Yes   | Credential value.      |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the credential is set successfully, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType or credential. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
738

A
annie_wangli 已提交
739
**Example**
A
annie_wangli 已提交
740

Z
zhangalong 已提交
741
  ```js
A
Annie_wang 已提交
742 743 744 745 746 747 748 749 750 751 752
  try {
    appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx", (err) => {
      if (err) {
        console.log("setCredential failed, error: " + JSON.stringify(err));
      } else {
        console.log("setCredential successfully");
      }
    });
  } catch (err) {
    console.log("setCredential exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
753 754
  ```

A
Annie_wang 已提交
755
### setCredential<sup>9+</sup>
A
annie_wangli 已提交
756

A
Annie_wang 已提交
757
setCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;
A
annie_wangli 已提交
758

A
Annie_wang 已提交
759
Sets a credential for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
760

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

A
annie_wangli 已提交
763
**Parameters**
A
annie_wangli 已提交
764

A
Annie_wang 已提交
765 766 767 768
| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.  |
| credentialType | string | Yes   | Type of the credential to set.|
A
Annie_wang 已提交
769
| credential     | string | Yes   | Credential value.   |
A
annie_wangli 已提交
770

A
Annie_wang 已提交
771
**Return value**
A
annie_wangli 已提交
772

A
Annie_wang 已提交
773
| Type                | Description                   |
A
Annie_wang 已提交
774
| :------------------ | :-------------------- |
A
Annie_wang 已提交
775 776 777 778 779 780 781 782 783
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType or credential. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
784 785

**Example**
A
annie_wangli 已提交
786

Z
zhangalong 已提交
787
  ```js
A
Annie_wang 已提交
788 789 790 791 792 793 794 795 796
  try {
    appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx").then(() => {
      console.log("setCredential successfully");
    }).catch((err) => {
      console.log("setCredential failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("setCredential exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
797 798
  ```

A
Annie_wang 已提交
799
### getCredential<sup>9+</sup>
A
annie_wangli 已提交
800

A
Annie_wang 已提交
801
getCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
802

A
Annie_wang 已提交
803
Obtains the credential of an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
804

A
annie_wangli 已提交
805 806 807
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
808

A
Annie_wang 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822
| Name           | Type                         | Mandatory  | Description            |
| -------------- | --------------------------- | ---- | -------------- |
| name           | string                      | Yes   | Name of the target app account.       |
| credentialType | string                      | Yes   | Type of the credential to obtain.|
| callback       | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
A
annie_wangli 已提交
823

A
annie_wangli 已提交
824
**Example**
A
annie_wangli 已提交
825

Z
zhangalong 已提交
826
  ```js
A
Annie_wang 已提交
827 828 829 830 831 832 833 834 835 836 837
  try {
      appAccountManager.getCredential("ZhangSan", "PIN_SIX", (err, result) => { 
        if (err) {
          console.log("getCredential failed, error: " + JSON.stringify(err));
        } else {
          console.log('getCredential successfully, result: ' + result);
        }
      });
  } catch (err) {
      console.log("getCredential err: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
838 839
  ```

A
Annie_wang 已提交
840
### getCredential<sup>9+</sup>
A
annie_wangli 已提交
841

A
Annie_wang 已提交
842
getCredential(name: string, credentialType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
843

A
Annie_wang 已提交
844
Obtains the credential of an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
845

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

A
annie_wangli 已提交
848
**Parameters**
A
annie_wangli 已提交
849

A
Annie_wang 已提交
850 851 852 853
| Name         | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.|
| credentialType | string | Yes   | Type of the credential to obtain.|
A
annie_wangli 已提交
854

A
Annie_wang 已提交
855
**Return value**
A
annie_wangli 已提交
856

A
Annie_wang 已提交
857 858 859 860 861 862 863 864 865 866 867 868
| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the credential obtained.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
A
annie_wangli 已提交
869 870

**Example**
A
annie_wangli 已提交
871

Z
zhangalong 已提交
872
  ```js
A
Annie_wang 已提交
873 874 875 876 877 878 879 880 881
  try {
    appAccountManager.getCredential("ZhangSan", "PIN_SIX").then((credential) => {
        console.log("getCredential successfully, credential: " + credential);
    }).catch((err) => {
        console.log("getCredential failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("getCredential exception: "  + JSON.stringify(err));
  }
A
annie_wangli 已提交
882 883
  ```

A
Annie_wang 已提交
884
### setCustomData<sup>9+</sup>
A
annie_wangli 已提交
885

A
Annie_wang 已提交
886
setCustomData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
887

A
Annie_wang 已提交
888
Sets custom data for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
889 890

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

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

A
Annie_wang 已提交
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
| Name     | Type                       | Mandatory  | Description               |
| -------- | ------------------------- | ---- | ----------------- |
| name     | string                    | Yes   | Name of the target app account.|
| key      | string                    | Yes   | Key of the custom data to set.|
| value    | string                    | Yes   | Value of the custom data to set.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or key or value. |
| 12300003 | Account not found. |
| 12400003 | The number of custom data reaches the upper limit. |
A
annie_wangli 已提交
909

A
annie_wangli 已提交
910
**Example**
A
annie_wangli 已提交
911

Z
zhangalong 已提交
912
  ```js
A
Annie_wang 已提交
913 914 915 916 917 918 919 920 921 922 923
  try {
    appAccountManager.setCustomData("ZhangSan", "age", "12", (err) => {
      if (err) {
        console.log("setCustomData failed, error: " + JSON.stringify(err));
      } else {
        console.log("setCustomData successfully");
      }
    });
  } catch (err) {
    console.log("setCustomData exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
924 925
  ```

A
Annie_wang 已提交
926
### setCustomData<sup>9+</sup>
A
annie_wangli 已提交
927

A
Annie_wang 已提交
928
setCustomData(name: string, key: string, value: string): Promise&lt;void&gt;
A
annie_wangli 已提交
929

A
Annie_wang 已提交
930
Sets custom data for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
931 932

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

A
annie_wangli 已提交
934
**Parameters**
A
annie_wangli 已提交
935

A
Annie_wang 已提交
936 937 938 939 940
| Name  | Type| Mandatory | Description             |
| ----- | ------ | ---- | ----------------- |
| name  | string | Yes   | Name of the target app account.  |
| key   | string | Yes   | Key of the custom data to set.|
| value | string | Yes   | Value of the custom data to set.|
A
annie_wangli 已提交
941

A
Annie_wang 已提交
942
**Return value**
A
annie_wangli 已提交
943

A
Annie_wang 已提交
944 945
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
946 947 948 949 950 951 952 953 954 955
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or key or value. |
| 12300003 | Account not found. |
| 12400003 | The number of custom data reaches the upper limit. |
A
annie_wangli 已提交
956

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

Z
zhangalong 已提交
959
  ```js
A
Annie_wang 已提交
960 961 962 963 964 965 966 967 968
  try {
    appAccountManager.setCustomData("ZhangSan", "age", "12").then(() => {
      console.log("setCustomData successfully");
    }).catch((err) => {
      console.log("setCustomData failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("setCustomData exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
969 970
  ```

A
Annie_wang 已提交
971
### getCustomData<sup>9+</sup>
A
annie_wangli 已提交
972

A
Annie_wang 已提交
973
getCustomData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
974

A
Annie_wang 已提交
975
Obtains the custom data of an app account based on the specified key. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
976

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

A
annie_wangli 已提交
979
**Parameters**
A
annie_wangli 已提交
980

A
Annie_wang 已提交
981 982 983 984 985 986 987 988 989 990 991 992 993 994
| Name   | Type                       | Mandatory | Description                    |
| -------- | --------------------------- | ----- | ------------------------ |
| name     | string                      | Yes   | Name of the target app account.          |
| key      | string                      | Yes   | Key of the custom data to obtain.        |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the custom data value obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
A
annie_wangli 已提交
995 996

**Example**
A
annie_wangli 已提交
997

Z
zhangalong 已提交
998
  ```js
A
Annie_wang 已提交
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
  try {
    appAccountManager.getCustomData("ZhangSan", "age", (err, data) => {
      if (err) {
        console.log('getCustomData failed, error: ' + err);
      } else {
        console.log("getCustomData successfully, data: " + data);
      }
    });
  } catch (err) {
    console.log("getCustomData exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1010 1011
  ```

A
Annie_wang 已提交
1012
### getCustomData<sup>9+</sup>
A
annie_wangli 已提交
1013

A
Annie_wang 已提交
1014
getCustomData(name: string, key: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1015

A
Annie_wang 已提交
1016
Obtains the custom data of an app account based on the specified key. This API uses a promise to return the result.
A
annie_wangli 已提交
1017

A
annie_wangli 已提交
1018 1019 1020
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1021

A
Annie_wang 已提交
1022 1023 1024 1025
| Name | Type    | Mandatory  | Description       |
| ---- | ------ | ---- | --------- |
| name | string | Yes   | Name of the target app account.  |
| key  | string | Yes   | Key of the custom data to obtain.|
A
annie_wangli 已提交
1026

A
Annie_wang 已提交
1027
**Return value**
A
annie_wangli 已提交
1028

A
Annie_wang 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
| Type                  | Description                   |
| --------------------- | --------------------- |
| Promise&lt;string&gt; | Promise used to return the custom data value obtained.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
A
annie_wangli 已提交
1041

A
annie_wangli 已提交
1042
**Example**
A
annie_wangli 已提交
1043

Z
zhangalong 已提交
1044
  ```js
A
Annie_wang 已提交
1045 1046 1047 1048 1049 1050 1051 1052 1053
  try {
    appAccountManager.getCustomData("ZhangSan", "age").then((data) => {
      console.log("getCustomData successfully, data: " + data);
    }).catch((err) => {
      console.log("getCustomData failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("getCustomData exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1054 1055
  ```

A
Annie_wang 已提交
1056
### getCustomDataSync<sup>9+</sup>
A
annie_wangli 已提交
1057

A
Annie_wang 已提交
1058
getCustomDataSync(name: string, key: string): string;
A
annie_wangli 已提交
1059

A
Annie_wang 已提交
1060
Obtains the custom data of an app account based on the specified key. The API returns the result synchronously.
A
annie_wangli 已提交
1061

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

A
annie_wangli 已提交
1064
**Parameters**
A
annie_wangli 已提交
1065

A
Annie_wang 已提交
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
| Name | Type    | Mandatory  | Description       |
| ---- | ------ | ---- | --------- |
| name | string | Yes   | Name of the target app account.  |
| key  | string | Yes   | Key of the custom data to obtain.|

**Return value**

| Type                   | Description                   |
| --------------------- | --------------------- |
| string | Value of the custom data obtained.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
A
annie_wangli 已提交
1085 1086

**Example**
A
annie_wangli 已提交
1087

Z
zhangalong 已提交
1088
  ```js
A
Annie_wang 已提交
1089 1090 1091 1092 1093 1094
  try {
      let value = appAccountManager.getCustomDataSync("ZhangSan", "age");
      console.info("getCustomDataSync successfully, vaue:" + value);
  } catch (err) {
    console.error("getCustomDataSync failed, error: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1095 1096
  ```

A
Annie_wang 已提交
1097
### getAllAccounts<sup>9+</sup>
A
annie_wangli 已提交
1098

A
Annie_wang 已提交
1099
getAllAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
1100

A
Annie_wang 已提交
1101 1102
Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result.

A
annie_wangli 已提交
1103 1104 1105
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1106

A
Annie_wang 已提交
1107 1108 1109
| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.|
A
annie_wangli 已提交
1110

A
Annie_wang 已提交
1111
**Error codes**
A
annie_wangli 已提交
1112

A
Annie_wang 已提交
1113 1114 1115
| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
A
annie_wangli 已提交
1116

A
annie_wangli 已提交
1117
**Example**
A
annie_wangli 已提交
1118

Z
zhangalong 已提交
1119
  ```js
A
Annie_wang 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
  try {
    appAccountManager.getAllAccounts((err, data) => {
      if (err) {
        console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
      } else {
        console.debug("getAllAccounts successfully");
      }
    });
  } catch (err) {
      console.debug("getAllAccounts exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1131 1132
  ```

A
Annie_wang 已提交
1133
### getAllAccounts<sup>9+</sup>
A
annie_wangli 已提交
1134

A
Annie_wang 已提交
1135 1136 1137
getAllAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Obtains information about all accessible app accounts. This API uses a promise to return the result.
A
annie_wangli 已提交
1138

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

A
Annie_wang 已提交
1141
**Return value**
A
annie_wangli 已提交
1142

A
Annie_wang 已提交
1143 1144 1145 1146 1147 1148 1149 1150 1151
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise used to return information about all accessible accounts.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
A
annie_wangli 已提交
1152 1153

**Example**
A
annie_wangli 已提交
1154

Z
zhangalong 已提交
1155
  ```js
A
Annie_wang 已提交
1156 1157 1158 1159 1160 1161 1162 1163 1164
  try {
    appAccountManager.getAllAccounts().then((data) => {
      console.debug("getAllAccounts successfully");
    }).catch((err) => {
      console.debug("getAllAccounts failed, error:" + JSON.stringify(err));
    });
  } catch (err) {
    console.debug("getAllAccounts exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1165 1166
  ```

A
Annie_wang 已提交
1167
### getAccountsByOwner<sup>9+</sup>
A
annie_wangli 已提交
1168

A
Annie_wang 已提交
1169 1170 1171
getAccountsByOwner(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void

Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1172

A
annie_wangli 已提交
1173 1174 1175
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1176

A
Annie_wang 已提交
1177 1178 1179 1180
| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.   |
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is null and **data** is the app account information obtained. Otherwise, **err** is an error object.|
A
annie_wangli 已提交
1181

A
Annie_wang 已提交
1182
**Error codes**
A
annie_wangli 已提交
1183

A
Annie_wang 已提交
1184 1185 1186 1187 1188
| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1189

A
annie_wangli 已提交
1190
**Example**
A
annie_wangli 已提交
1191

Z
zhangalong 已提交
1192
  ```js
A
Annie_wang 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
  try {
    appAccountManager.getAccountsByOwner("com.example.accountjsdemo2", (err, data) => {
      if (err) {
        console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
      } else {
        console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
      }
    });
  } catch (err) {
    console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
  }
A
annie_wangli 已提交
1204 1205
  ```

A
Annie_wang 已提交
1206
### getAccountsByOwner<sup>9+</sup>
A
annie_wangli 已提交
1207

A
Annie_wang 已提交
1208
getAccountsByOwner(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
A
annie_wangli 已提交
1209

A
Annie_wang 已提交
1210 1211
Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result.

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

A
annie_wangli 已提交
1214
**Parameters**
A
annie_wangli 已提交
1215

A
Annie_wang 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
| Name  | Type    | Mandatory  | Description    |
| ----- | ------ | ---- | ------ |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|

**Return value**

| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise used to return the app account information obtained.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1233 1234

**Example**
A
annie_wangli 已提交
1235

Z
zhangalong 已提交
1236
  ```js
A
Annie_wang 已提交
1237 1238 1239 1240 1241 1242 1243 1244 1245
  try {
    appAccountManager.getAccountsByOwner("com.example.accountjsdemo2").then((data) => {
      console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data));
    }).catch((err) => {
      console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err));
    });
  } catch (err) {
    console.debug("getAccountsByOwner exception:" + JSON.stringify(err));
  }
A
annie_wangli 已提交
1246 1247
  ```

A
Annie_wang 已提交
1248
### on('accountChange')<sup>9+</sup>
A
annie_wangli 已提交
1249

A
Annie_wang 已提交
1250
on(type: 'accountChange', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
1251

A
Annie_wang 已提交
1252
Subscribes to account information changes of apps.
A
annie_wangli 已提交
1253

A
annie_wangli 已提交
1254 1255 1256
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1257

A
Annie_wang 已提交
1258 1259 1260 1261 1262
| Name     | Type                                      | Mandatory  | Description                            |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| type     | 'accountChange'                          | Yes   | Event type to subscribe to. The value is **'accountChange'**. An event will be reported when the account information of the target app changes.|
| owners   | Array&lt;string&gt;                      | Yes   | App bundle names of the account.                     |
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return a list of app accounts whose information is changed.          |
A
annie_wangli 已提交
1263

A
Annie_wang 已提交
1264
**Error codes**
A
annie_wangli 已提交
1265

A
Annie_wang 已提交
1266 1267 1268 1269 1270 1271
| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or owners. |
| 12300011 | Callback has been registered. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1272

A
annie_wangli 已提交
1273
**Example**
A
annie_wangli 已提交
1274

Z
zhangalong 已提交
1275
  ```js
A
Annie_wang 已提交
1276 1277 1278 1279 1280 1281 1282 1283
  function changeOnCallback(data){
  	console.log("receive change data:" + JSON.stringify(data));
  }
  try{
  	appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
  } catch(err) {
  	console.error("on accountChange failed, error:" + JSON.stringify(err));
  }
A
annie_wangli 已提交
1284 1285
  ```

A
Annie_wang 已提交
1286
### off('accountChange')<sup>9+</sup>
A
Annie_wang 已提交
1287

A
Annie_wang 已提交
1288
off(type: 'accountChange', callback?: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
Annie_wang 已提交
1289

A
Annie_wang 已提交
1290
Unsubscribes from account information changes.
A
Annie_wang 已提交
1291 1292 1293 1294 1295

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
1296 1297 1298
| Name     | Type                              | Mandatory  | Description          |
| -------- | -------------------------------- | ---- | ------------ |
| type     | 'accountChange'                         | Yes   | Event type to unsubscribe from. The value is **'accountChange'**.   |
A
Annie_wang 已提交
1299
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | No   | Callback to unregister.|
A
Annie_wang 已提交
1300

A
Annie_wang 已提交
1301
**Error codes**
A
Annie_wang 已提交
1302

A
Annie_wang 已提交
1303 1304 1305 1306 1307
| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid type. |
| 12300012 | Callback has not been registered. |
A
Annie_wang 已提交
1308 1309 1310 1311

**Example**

  ```js
A
Annie_wang 已提交
1312
  function changeOnCallback(data) {
A
Annie_wang 已提交
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
  	console.log("receive change data:" + JSON.stringify(data));
  }
  try{
  	appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback);
  } catch(err) {
  	console.error("on accountChange failed, error:" + JSON.stringify(err));
  }
  try{
  	appAccountManager.off('accountChange', changeOnCallback);
  }
  catch(err){
  	console.error("off accountChange failed, error:" + JSON.stringify(err));
  }
A
Annie_wang 已提交
1326 1327
  ```

A
Annie_wang 已提交
1328
### auth<sup>9+</sup>
A
annie_wangli 已提交
1329

A
Annie_wang 已提交
1330
auth(name: string, owner: string, authType: string, callback: AuthCallback): void
A
annie_wangli 已提交
1331

A
Annie_wang 已提交
1332
Authenticates an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1333

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

A
annie_wangli 已提交
1336
**Parameters**
A
annie_wangli 已提交
1337

A
Annie_wang 已提交
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
| name     | string                | Yes   | Name of the target app account.    |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                | Yes   | Authentication type.          |
| callback | [AuthCallback](#authcallback9) | Yes   | Callback invoked to return the authentication result.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or authType. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
A
annie_wangli 已提交
1355 1356

**Example**
A
annie_wangli 已提交
1357

Z
zhangalong 已提交
1358
  ```js
A
Annie_wang 已提交
1359

A
annie_wangli 已提交
1360

A
Annie_wang 已提交
1361 1362 1363 1364
  function onResultCallback(code, authResult) {
    console.log("resultCode: "  + code);
    console.log("authResult: "  + JSON.stringify(authResult));
  }
A
annie_wangli 已提交
1365

A
Annie_wang 已提交
1366
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
      console.log("startAbility err: " + JSON.stringify(err));
    })
A
Annie_wang 已提交
1378
  }
A
annie_wangli 已提交
1379

A
Annie_wang 已提交
1380 1381 1382 1383 1384 1385 1386 1387 1388
  try {
    appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", {
        onResult: onResultCallback,
        onRequestRedirected: onRequestRedirectedCallback
    });
  } catch (err) {
    console.log("auth exception: "  + JSON.stringify(err));
  }
  ```
A
annie_wangli 已提交
1389

A
Annie_wang 已提交
1390
### auth<sup>9+</sup>
A
annie_wangli 已提交
1391

A
Annie_wang 已提交
1392
auth(name: string, owner: string, authType: string, options: {[key: string]: Object}, callback: AuthCallback): void
A
annie_wangli 已提交
1393

A
Annie_wang 已提交
1394
Authenticates an app account with customized options. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1395

A
annie_wangli 已提交
1396 1397 1398
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1399

A
Annie_wang 已提交
1400 1401
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
1402
| name     | string                | Yes   | Name of the target app account.    |
A
Annie_wang 已提交
1403 1404
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                | Yes   | Authentication type.          |
A
Annie_wang 已提交
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
| options  | {[key: string]: Object}  | Yes   | Options for the authentication.      |
| callback | [AuthCallback](#authcallback9) | Yes   | Callback invoked to return the authentication result.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or authType. |
| 12300003 | Account not exist. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
A
annie_wangli 已提交
1418

A
annie_wangli 已提交
1419
**Example**
A
annie_wangli 已提交
1420

Z
zhangalong 已提交
1421
  ```js
A
Annie_wang 已提交
1422

A
annie_wangli 已提交
1423

A
Annie_wang 已提交
1424 1425 1426
  function onResultCallback(code, authResult) {
    console.log("resultCode: "  + code);
    console.log("authResult: "  + JSON.stringify(authResult));
A
annie_wangli 已提交
1427
  }
A
annie_wangli 已提交
1428

A
annie_wangli 已提交
1429
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
      console.log("startAbility err: " + JSON.stringify(err));
    })
A
annie_wangli 已提交
1441
  }
A
annie_wangli 已提交
1442

A
Annie_wang 已提交
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
  let options = {
    "password": "xxxx",
  };
  try {
    appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", options, {
        onResult: onResultCallback,
        onRequestRedirected: onRequestRedirectedCallback
    });
  } catch (err) {
    console.log("auth exception: "  + JSON.stringify(err));
  }
A
annie_wangli 已提交
1454 1455
  ```

A
Annie_wang 已提交
1456
### getAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1457

A
Annie_wang 已提交
1458
getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1459

A
Annie_wang 已提交
1460
Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1461

A
annie_wangli 已提交
1462 1463 1464
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1465

A
Annie_wang 已提交
1466 1467 1468 1469 1470
| Name     | Type                         | Mandatory  | Description         |
| -------- | --------------------------- | ---- | ----------- |
| name     | string                      | Yes   | Name of the target app account.   |
| owner    | string                      | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string                      | Yes   | Authentication type.      |
A
Annie_wang 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object.   |

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1481

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

Z
zhangalong 已提交
1484
  ```js
A
Annie_wang 已提交
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
  try {
    appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, token) => {
      if (err) {
        console.log("getAuthToken failed, error: " + JSON.stringify(err));
      } else {
        console.log("getAuthToken successfully, token: " + token);
      }
    });
  } catch (err) {
      console.log("getAuthToken exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1496 1497
  ```

A
Annie_wang 已提交
1498
### getAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1499

A
Annie_wang 已提交
1500
getAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1501

A
Annie_wang 已提交
1502
Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1503

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

A
annie_wangli 已提交
1506
**Parameters**
A
annie_wangli 已提交
1507

A
Annie_wang 已提交
1508 1509 1510 1511 1512
| Name     | Type    | Mandatory  | Description         |
| -------- | ------ | ---- | ----------- |
| name     | string | Yes   | Name of the target app account.   |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string | Yes   | Authentication type.      |
A
annie_wangli 已提交
1513

A
Annie_wang 已提交
1514
**Return value**
A
annie_wangli 已提交
1515

A
Annie_wang 已提交
1516
| Type                   | Description                |
A
Annie_wang 已提交
1517
| --------------------- | --------------------- |
A
Annie_wang 已提交
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
| Promise&lt;string&gt; | Promise used to return the authorization token obtained.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1528 1529

**Example**
A
annie_wangli 已提交
1530

Z
zhangalong 已提交
1531
  ```js
A
Annie_wang 已提交
1532 1533 1534 1535 1536 1537 1538 1539 1540
  try {
    appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((token) => {
      console.log("getAuthToken successfully, token: " + token);
    }).catch((err) => {
      console.log("getAuthToken failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
      console.log("getAuthToken exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1541 1542
  ```

A
Annie_wang 已提交
1543
### setAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1544

A
Annie_wang 已提交
1545
setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1546

A
Annie_wang 已提交
1547
Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1548

A
annie_wangli 已提交
1549 1550 1551
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1552

A
Annie_wang 已提交
1553 1554 1555 1556
| Name     | Type                       | Mandatory  | Description      |
| -------- | ------------------------- | ---- | -------- |
| name     | string                    | Yes   | Name of the target app account.|
| authType | string                    | Yes   | Authentication type.   |
A
Annie_wang 已提交
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
| token    | string                    | Yes   | Token to set.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or token. |
| 12300003 | Account not found. |
| 12400004 | The number of token reaches the upper limit. |
A
annie_wangli 已提交
1568

A
annie_wangli 已提交
1569
**Example**
A
annie_wangli 已提交
1570

Z
zhangalong 已提交
1571
  ```js
A
Annie_wang 已提交
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
  try {
    appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
      if (err) {
        console.log("setAuthToken failed, error: " + JSON.stringify(err));
      } else {
        console.log("setAuthToken successfully");
      }
    });
  } catch (err) {
      console.log('setAuthToken exception: ' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1583 1584
  ```

A
Annie_wang 已提交
1585
### setAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1586

A
Annie_wang 已提交
1587
setAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1588

A
Annie_wang 已提交
1589
Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1590

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

A
annie_wangli 已提交
1593
**Parameters**
A
annie_wangli 已提交
1594

A
Annie_wang 已提交
1595 1596 1597 1598
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| name     | string | Yes   | Name of the target app account.|
| authType | string | Yes   | Authentication type.   |
A
Annie_wang 已提交
1599
| token    | string | Yes   | Token to set.|
A
annie_wangli 已提交
1600

A
Annie_wang 已提交
1601
**Return value**
A
annie_wangli 已提交
1602

A
Annie_wang 已提交
1603 1604
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or token. |
| 12300003 | Account not found. |
| 12400004 | The number of token reaches the upper limit. |
A
annie_wangli 已提交
1615 1616

**Example**
A
annie_wangli 已提交
1617

Z
zhangalong 已提交
1618
  ```js
A
Annie_wang 已提交
1619 1620 1621 1622 1623 1624 1625 1626 1627
  try {
    appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
        console.log("setAuthToken successfully");
    }).catch((err) => {
        console.log("setAuthToken failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("setAuthToken exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1628 1629
  ```

A
Annie_wang 已提交
1630
### deleteAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1631

A
Annie_wang 已提交
1632
deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1633

A
Annie_wang 已提交
1634
Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1635

A
annie_wangli 已提交
1636 1637 1638
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1639

A
Annie_wang 已提交
1640 1641 1642 1643 1644
| Name     | Type                       | Mandatory  | Description          |
| -------- | ------------------------- | ---- | ------------ |
| name     | string                    | Yes   | Name of the target app account.    |
| owner    | string                    | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                    | Yes   | Authentication type.       |
A
Annie_wang 已提交
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
| token    | string                    | Yes   | Token to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.    |

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or authType or token. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1656

A
annie_wangli 已提交
1657
**Example**
A
annie_wangli 已提交
1658

Z
zhangalong 已提交
1659
  ```js
A
Annie_wang 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
  try {
      appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
        if (err) {
          console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
        } else {
          console.log("deleteAuthToken successfully");
        }
      });
  } catch (err) {
      console.log('deleteAuthToken exception: ' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1671 1672
  ```

A
Annie_wang 已提交
1673
### deleteAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1674

A
Annie_wang 已提交
1675
deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1676

A
Annie_wang 已提交
1677
Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1678

A
annie_wangli 已提交
1679 1680 1681
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1682

A
Annie_wang 已提交
1683 1684 1685 1686 1687
| Name     | Type    | Mandatory  | Description          |
| -------- | ------ | ---- | ------------ |
| name     | string | Yes   | Name of the target app account.    |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string | Yes   | Authentication type.       |
A
Annie_wang 已提交
1688
| token    | string | Yes   | Authorization token to delete.|
A
annie_wangli 已提交
1689

A
Annie_wang 已提交
1690
**Return value**
A
annie_wangli 已提交
1691

A
Annie_wang 已提交
1692 1693
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or authType or token. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1704

A
annie_wangli 已提交
1705
**Example**
A
annie_wangli 已提交
1706

Z
zhangalong 已提交
1707
  ```js
A
Annie_wang 已提交
1708 1709 1710 1711 1712 1713 1714 1715 1716
  try {
    appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
      console.log("deleteAuthToken successfully");
    }).catch((err) => {
      console.log('deleteAuthToken failed, error: ' + JSON.stringify(err));
    });
  } catch (err) {
    console.log('deleteAuthToken exception: ' + JSON.stringify(err));
  }
A
annie_wangli 已提交
1717 1718
  ```

A
Annie_wang 已提交
1719
### setAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1720

A
Annie_wang 已提交
1721
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1722

A
Annie_wang 已提交
1723
Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1724

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

A
annie_wangli 已提交
1727
**Parameters**
A
annie_wangli 已提交
1728

A
Annie_wang 已提交
1729 1730 1731 1732 1733
| Name       | Type                       | Mandatory  | Description                       |
| ---------- | ------------------------- | ---- | ------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| authType   | string                    | Yes   | Authentication type.                    |
| bundleName | string                    | Yes   | Bundle name of the app.             |
A
Annie_wang 已提交
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
| isVisible  | boolean                   | Yes   | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400001 | Application not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
A
annie_wangli 已提交
1747 1748

**Example**
A
annie_wangli 已提交
1749

Z
zhangalong 已提交
1750
  ```js
A
Annie_wang 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
  try {
      appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
        if (err) {
          console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
        } else {
          console.log("setAuthTokenVisibility successfully");
        }
      });
  } catch (err) {
      console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1762 1763
  ```

A
Annie_wang 已提交
1764
### setAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1765

A
Annie_wang 已提交
1766
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
1767

A
Annie_wang 已提交
1768
Sets the visibility of an authorization token to an app. This API uses a promise to return the result.
A
annie_wangli 已提交
1769

A
annie_wangli 已提交
1770 1771 1772
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1773

A
Annie_wang 已提交
1774 1775 1776 1777 1778 1779
| Name     | Type                       | Mandatory  | Description                       |
| ---------- | ------------------------- | ---- | ------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| authType   | string                    | Yes   | Authentication type.                    |
| bundleName | string                    | Yes   | Bundle name of the app.             |
| isVisible  | boolean                   | Yes   | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.|
A
annie_wangli 已提交
1780

A
Annie_wang 已提交
1781
**Return value**
A
annie_wangli 已提交
1782

A
Annie_wang 已提交
1783 1784
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400001 | Application not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
A
annie_wangli 已提交
1797

A
annie_wangli 已提交
1798
**Example**
A
annie_wangli 已提交
1799

Z
zhangalong 已提交
1800
  ```js
A
Annie_wang 已提交
1801 1802 1803 1804 1805 1806 1807 1808 1809
  try {
    appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
      console.log("setAuthTokenVisibility successfully");
    }).catch((err) => {
      console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("setAuthTokenVisibility exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1810 1811
  ```

A
Annie_wang 已提交
1812
### checkAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1813

A
Annie_wang 已提交
1814
checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
1815

A
Annie_wang 已提交
1816
Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1817

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

A
annie_wangli 已提交
1820
**Parameters**
A
annie_wangli 已提交
1821

A
Annie_wang 已提交
1822 1823 1824 1825 1826
| Name       | Type                          | Mandatory  | Description         |
| ---------- | ---------------------------- | ---- | ----------- |
| name       | string                       | Yes   | Name of the target app account.   |
| authType   | string                       | Yes   | Authentication type.      |
| bundleName | string                       | Yes   | Bundle name of the app.|
A
Annie_wang 已提交
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837
| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object.   |

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1838 1839

**Example**
A
annie_wangli 已提交
1840

Z
zhangalong 已提交
1841
  ```js
A
Annie_wang 已提交
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
  try {
    appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, isVisible) => {
      if (err) {
        console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
      } else {
        console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
      }
    });
  } catch (err) {
    console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1853 1854
  ```

A
Annie_wang 已提交
1855
### checkAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1856

A
Annie_wang 已提交
1857
checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
1858

A
Annie_wang 已提交
1859
Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result.
A
annie_wangli 已提交
1860

A
annie_wangli 已提交
1861 1862 1863
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1864

A
Annie_wang 已提交
1865 1866 1867 1868 1869
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
| name       | string | Yes   | Name of the target app account.     |
| authType   | string | Yes   | Authentication type.        |
| bundleName | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1870

A
Annie_wang 已提交
1871
**Return value**
A
annie_wangli 已提交
1872

A
Annie_wang 已提交
1873 1874
| Type                    | Description                   |
| ---------------------- | --------------------- |
A
Annie_wang 已提交
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1886

A
annie_wangli 已提交
1887
**Example**
A
annie_wangli 已提交
1888

Z
zhangalong 已提交
1889
  ```js
A
Annie_wang 已提交
1890 1891 1892 1893 1894 1895 1896 1897 1898
  try {
    appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((isVisible) => {
      console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible);
    }).catch((err) => {
      console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err));
  }
A
annie_wangli 已提交
1899 1900
  ```

A
Annie_wang 已提交
1901
### getAllAuthTokens<sup>9+</sup>
A
annie_wangli 已提交
1902

A
Annie_wang 已提交
1903
getAllAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;AuthTokenInfo&gt;&gt;): void
A
annie_wangli 已提交
1904

A
Annie_wang 已提交
1905
Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1906

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

A
annie_wangli 已提交
1909
**Parameters**
A
annie_wangli 已提交
1910

A
Annie_wang 已提交
1911 1912 1913 1914
| Name     | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| name     | string                                   | Yes   | Name of the target app account.   |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
1915 1916 1917 1918 1919 1920 1921 1922 1923
| callback | AsyncCallback&lt;Array&lt;[AuthTokenInfo](#authtokeninfo9)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object.   |

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner. |
| 12300003 | Account not found. |
A
annie_wangli 已提交
1924 1925

**Example**
A
annie_wangli 已提交
1926

Z
zhangalong 已提交
1927
  ```js
A
Annie_wang 已提交
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938
  try {
    appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo", (err, tokenArr) => {
      if (err) {
        console.log("getAllAuthTokens failed, error: "  + JSON.stringify(err));
      } else {
        console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
      }
    });
  } catch (err) {
    console.log("getAllAuthTokens exception: "  + JSON.stringify(err));
  }
A
annie_wangli 已提交
1939 1940
  ```

A
Annie_wang 已提交
1941
### getAllAuthTokens<sup>9+</sup>
A
annie_wangli 已提交
1942

A
Annie_wang 已提交
1943
getAllAuthTokens(name: string, owner: string): Promise&lt;Array&lt;AuthTokenInfo&gt;&gt;
A
annie_wangli 已提交
1944

A
Annie_wang 已提交
1945
Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1946

A
annie_wangli 已提交
1947 1948 1949
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1950

A
Annie_wang 已提交
1951 1952 1953 1954
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| name  | string | Yes   | Name of the target app account.   |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
annie_wangli 已提交
1955

A
Annie_wang 已提交
1956
**Return value**
A
annie_wangli 已提交
1957

A
Annie_wang 已提交
1958 1959
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378
| Promise&lt;Array&lt;[AuthTokenInfo](#authtokeninfo9)&gt;&gt; | Promise used to return the tokens obtained.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner. |
| 12300003 | Account not found. |

**Example**

  ```js
  try {
    appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo").then((tokenArr) => {
        console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
    }).catch((err) => {
        console.log("getAllAuthTokens failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log("getAllAuthTokens exception: "  + JSON.stringify(err));
  }
  ```

### getAuthList<sup>9+</sup>

getAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                                      | Mandatory  | Description                     |
| -------- | ---------------------------------------- | ---- | ----------------------- |
| name     | string                                   | Yes   | Name of the target app account.               |
| authType | string                                   | Yes   | Authentication type.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |

**Example**

  ```js
  try {
    appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData", (err, authList) => {
      if (err) {
        console.log("getAuthList failed, error: " + JSON.stringify(err));
      } else {
        console.log("getAuthList successfully, authList: " + authList);
      }
    });
  } catch (err) {
    console.log('getAuthList exception: ' + JSON.stringify(err));
  }
  ```

### getAuthList<sup>9+</sup>

getAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;

Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type    | Mandatory  | Description                     |
| -------- | ------ | ---- | ------------------------------ |
| name     | string | Yes   | Name of the target app account.               |
| authType | string | Yes   | Authentication type.|

**Return value**

| Type                                | Description                   |
| ---------------------------------- | --------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return a list of authorized bundles.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |

**Example**

  ```js
  try {
    appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData").then((authList) => {
        console.log("getAuthList successfully, authList: " + authList);
    }).catch((err) => {
        console.log("getAuthList failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log("getAuthList exception: "  + JSON.stringify(err));
  }
  ```

### getAuthCallback<sup>9+</sup>

getAuthCallback(sessionId: string, callback: AsyncCallback&lt;AuthCallback&gt;): void

Obtains the authenticator callback for the authentication session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type                                      | Mandatory  | Description      |
| --------- | ---------------------------------------- | ---- | -------- |
| sessionId | string                                   | Yes   | ID of the authentication session.|
| callback  | AsyncCallback&lt;[AuthCallback](#authcallback9)&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback object obtained. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid sessionId. |
| 12300108 | Session not found. |

**Example**

  ```js
  import featureAbility from '@ohos.ability.featureAbility';
  featureAbility.getWant((err, want) => {
    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
    try {
      appAccountManager.getAuthCallback(sessionId, (err, callback) => {
        if (err.code != account_appAccount.ResultCode.SUCCESS) {
            console.log("getAuthCallback err: "  + JSON.stringify(err));
            return;
        }
        var result = {
          accountInfo: {
            name: "Lisi",
            owner: "com.example.accountjsdemo",
          },
          tokenInfo: {
            token: "xxxxxx",
            authType: "getSocialData"
          }
        }; 
        callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
      });
    } catch (err) {
        console.log("getAuthCallback exception: "  + JSON.stringify(err));
    }
  });
  ```

### getAuthCallback<sup>9+</sup>

getAuthCallback(sessionId: string): Promise&lt;AuthCallback&gt;

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

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type    | Mandatory  | Description      |
| --------- | ------ | ---- | -------- |
| sessionId | string | Yes   | ID of the authentication session.|

**Return value**

| Type                                  | Description                   |
| ------------------------------------ | --------------------- |
| Promise&lt;[AuthCallback](#authcallback9)&gt; | Promise used to return the authenticator callback obtained.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid sessionId. |
| 12300108 | Session not found. |

**Example**

  ```js
  import featureAbility from '@ohos.ability.featureAbility';

  featureAbility.getWant().then((want) => {
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
      try {
        appAccountManager.getAuthCallback(sessionId).then((callback) => {
        var result = {
          accountInfo: {
            name: "Lisi",
            owner: "com.example.accountjsdemo",
          },
          tokenInfo: {
            token: "xxxxxx",
            authType: "getSocialData"
          }
        };
        callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
        }).catch((err) => {
            console.log("getAuthCallback err: "  + JSON.stringify(err));
        });
      } catch (err) {
        console.log("getAuthCallback exception: "  + JSON.stringify(err));
      }
  }).catch((err) => {
      console.log("getWant err: "  + JSON.stringify(err));
  });
  ```

### queryAuthenticatorInfo<sup>9+</sup>

queryAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void

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

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                                    | Mandatory  | Description         |
| -------- | -------------------------------------- | ---- | ----------- |
| owner    | string                                 | Yes   | Bundle name of the app.|
| callback | AsyncCallback&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object.   |

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300113 | Authenticator service not found. |

**Example**

  ```js
  try {
    appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo", (err, info) => {
      if (err) {
        console.log("queryAuthenticatorInfo failed, error: "  + JSON.stringify(err));
      } else {
        console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
      }
    });
  } catch (err) {
    console.log("queryAuthenticatorInfo exception: "  + JSON.stringify(err));
  }
  ```

### queryAuthenticatorInfo<sup>9+</sup>

queryAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;

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

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Bundle name of the app.|

**Return value**

| Type                              | Description                   |
| -------------------------------- | --------------------- |
| Promise&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Promise used to return the authenticator information obtained.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300113 | Authenticator service not found. |

**Example**

  ```js
  try {
    appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo").then((info) => { 
        console.log("queryAuthenticatorInfo successfully, info: " + JSON.stringify(info));
    }).catch((err) => {
        console.log("queryAuthenticatorInfo failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log("queryAuthenticatorInfo exception: "  + JSON.stringify(err));
  }
  ```

### checkAccountLabels<sup>9+</sup>

checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;, callback: AsyncCallback&lt;boolean&gt;): void;

Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target app.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
| name           | string                    | Yes   | Name of the target app account. |
| owner          | string                    | Yes   | Owner of the app account. The value is the bundle name of the app.|
| labels         | Array&lt;string&gt;       | Yes   | Labels to check.      |
| callback       | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** or **false**. The value **true** means the app account has the labels; the value **false** means the opposite. If the operation fails, **err** is an error object. |

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or labels. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let labels = ["student"];
  try {
    appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels, (err, hasAllLabels) => {
      if (err) {
        console.log("checkAccountLabels failed, error: "  + JSON.stringify(err));
      } else {
        console.log("checkAccountLabels successfully, hasAllLabels: " + hasAllLabels);
      }
    });
  } catch (err) {
    console.log("checkAccountLabels exception: "  + JSON.stringify(err));
  }
  ```

### checkAccountLabels<sup>9+</sup>

checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;): Promise&lt;boolean&gt;

Checks whether an app account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target app.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
| name           | string                    | Yes   | Name of the target app account. |
| owner          | string                    | Yes   | Owner of the app account. The value is the bundle name of the app.|
| labels         | Array&lt;string&gt;       | Yes   | Labels to check.      |

**Return value**

| Type               | Description                             |
| ------------------- | -------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the app account has the labels; the value **false** means the opposite.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or labels. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let labels = ["student"];
  try {
    appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels).then((hasAllLabels) => {
      console.log('checkAccountLabels successfully: ' + hasAllLabels);
    }).catch((err) => {
      console.log("checkAccountLabels failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log("checkAccountLabels exception: "  + JSON.stringify(err));
  }
  ```

### deleteCredential<sup>9+</sup>

deleteCredential(name: string, credentialType: string, callback: AsyncCallback&lt;void&gt;): void

Deletes the credential of the specified type from an app account. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description           |
| -------------- | ------------------------- | ----- | -------------- |
| name           | string                    | Yes   | Name of the target app account.|
| credentialType | string                    | Yes   | Type of the credential to delete.     |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
A
annie_wangli 已提交
2379

A
annie_wangli 已提交
2380
**Example**
A
annie_wangli 已提交
2381

A
Annie_wang 已提交
2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732
  ```js
  try {
    appAccountManager.deleteCredential("zhangsan", "PIN_SIX", (err) => {
      if (err) {
        console.log("deleteCredential failed, error: "  + JSON.stringify(err));
      } else {
        console.log("deleteCredential successfully");
      }
    });
  } catch (err) {
    console.log("deleteCredential exception: "  + JSON.stringify(err));
  }
  ```

### deleteCredential<sup>9+</sup>

deleteCredential(name: string, credentialType: string): Promise&lt;void&gt;

Deletes the credential of the specified type from an app account. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type  | Mandatory  | Description           |
| -------------- | ------ | ----- | --------------- |
| name           | string | Yes   | Name of the target app account.|
| credentialType | string | Yes   | Type of the credential to delete.      |

**Return value**

| Type               | Description                             |
| ------------------- | -------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |

**Example**

  ```js
  try {
    appAccountManager.deleteCredential("zhangsan", "PIN_SIX").then(() => {
      console.log("deleteCredential successfully");
    }).catch((err) => {
      console.log("deleteCredential failed, error: " + JSON.stringify(err));
    });
  } catch (err) {
    console.log("deleteCredential exception: "  + JSON.stringify(err));
  }
  ```

### selectAccountsByOptions<sup>9+</sup>

selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void

Selects the accounts that can be accessed by the invoker based on the options. This API uses an asynchronous callback to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                                | Mandatory | Description            |
| -------------- | ----------------------------------- | ----- | --------------- |
| options        | SelectAccountsOptions               | Yes   | Options for selecting accounts. |
| callback       | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accounts selected. Otherwise, **err** is an error object. |

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid options. |
| 12300010 | Account service busy. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let options = {
    allowedOwners: [ "com.example.accountjsdemo" ],
    requiredLabels: [ "student" ]
  };
  try {
    appAccountManager.selectAccountsByOptions(options, (err, accountArr) => {
      if (err) {
        console.log("selectAccountsByOptions failed, error: "  + JSON.stringify(err));
      } else {
        console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
      }
    });
  } catch (err) {
    console.log("selectAccountsByOptions exception: "  + JSON.stringify(err));
  }
  ```

### selectAccountsByOptions<sup>9+</sup>

selectAccountsByOptions(options: SelectAccountsOptions): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Selects the accounts that can be accessed by the invoker based on the options. This API uses a promise to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
| options        | [SelectAccountsOptions](#selectaccountsoptions9)     | Yes   | Options for selecting accounts. |

**Return value**

| Type               | Description                             |
| ------------------- | -------------------------------- |
| Promise&lt;[AppAccountInfo](#appaccountinfo)&gt; | Promise used to return the accounts selected.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid options. |
| 12300010 | Account service busy. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let options = {
    allowedOwners: ["com.example.accountjsdemo"]
  };
  try {
    appAccountManager.selectAccountsByOptions(options).then((accountArr) => {
      console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr));
    }).catch((err) => {
      console.log("selectAccountsByOptions failed, error: "  + JSON.stringify(err));
    });
  } catch (err) {
    console.log("selectAccountsByOptions exception: "  + JSON.stringify(err));
  }
  ```

### verifyCredential<sup>9+</sup>

verifyCredential(name: string, owner: string, callback: AuthCallback): void;

Verifies the credential of an app account. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| name     | string                | Yes   | Name of the target app account.         |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app.       |
| callback | [AuthCallback](#authcallback9) | Yes   | Callback invoked to return the result.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  try {
      appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", {
          onResult: (resultCode, result) => {
              console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
              console.log("verifyCredential onResult, result:" + JSON.stringify(result));
          },
          onRequestRedirected: (request) => {
              console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
          }
      });
  } catch (err) {
      console.log("verifyCredential err: "  + JSON.stringify(err));
  }
  ```

### verifyCredential<sup>9+</sup>

verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void;

Verifies the user credential. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                   | Mandatory | Description                    |
| -------- | ----------------------- | ----- | ----------------------- |
| name     | string                  | Yes   | Name of the target app account.         |
| owner    | string                  | Yes   | Owner of the app account. The value is the bundle name of the app.       |
| options  | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes   | Options for verifying the user credential.         |
| callback | [AuthCallback](#authcallback9)   | Yes   | Callback invoked to return the result.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner or options. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let options = {
    credentialType: "pin",
    credential: "123456"
  };
  try {
    appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", options, {
      onResult: (resultCode, result) => {
        console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
        console.log("verifyCredential onResult, result:" + JSON.stringify(result));
      },
      onRequestRedirected: (request) => {
        console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
      }
    });
  } catch (err) {
    console.log("verifyCredential err: "  + JSON.stringify(err));
  }
  ```

### setAuthenticatorProperties<sup>9+</sup>

setAuthenticatorProperties(owner: string, callback: AuthCallback): void;

Sets the authenticator attributes of an app. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| owner    | string                | Yes   | Owner of the authenticator.         |
| callback | [AuthCallback](#authcallback9) | Yes   | Callback invoked to return the result.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  try {
    appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", {
      onResult: (resultCode, result) => {
        console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
        console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
      },
      onRequestRedirected: (request) => {
        console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
      }
    });
  } catch (err) {
    console.log("setAuthenticatorProperties err: "  + JSON.stringify(err));
  }
  ```

### setAuthenticatorProperties<sup>9+</sup>

setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void;

Set authenticator properties. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| owner    | string                | Yes   | Owner of the authenticator.         |
| options  | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.         |
| callback | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|

**Error codes**

| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid owner or options. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |

**Example**

  ```js
  let options = {
    properties: {"prop1": "value1"}
  };
  try {
    appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", options, {
      onResult: (resultCode, result) => {
        console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
        console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
      },
      onRequestRedirected: (request) => {
        console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
      }
    });
  } catch (err) {
    console.log("setAuthenticatorProperties err: "  + JSON.stringify(err));
  } 

  ```

### addAccount<sup>(deprecated)</sup>

addAccount(name: string, callback: AsyncCallback&lt;void&gt;): void

Adds an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
> 
>This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9).


**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                       | Mandatory  | Description                  |
| -------- | ------------------------- | ---- | -------------------- |
A
Annie_wang 已提交
2733
| name     | string                    | Yes   | Name of the app account to add.         |
A
Annie_wang 已提交
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.addAccount("WangWu", (err) => { 
      console.log("addAccount err: " + JSON.stringify(err));
  });
  ```

### addAccount<sup>(deprecated)</sup>

addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void

Adds an app account name and additional information. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
2751
> 
A
Annie_wang 已提交
2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type                       | Mandatory  | Description                                      |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| name      | string                    | Yes   | Name of the target app account.                             |
| extraInfo | string                    | Yes   | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.|
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.            |

**Example**

  ```js
  appAccountManager.addAccount("LiSi", "token101", (err) => { 
    console.log("addAccount err: " + JSON.stringify(err));
  });
  ```

### addAccount<sup>(deprecated)</sup>

addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;

Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result.

A
Annie_wang 已提交
2778
> **NOTE**<br> 
A
Annie_wang 已提交
2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type    | Mandatory  | Description                                      |
| --------- | ------ | ---- | ---------------------------------------- |
| name      | string | Yes   | Name of the target app account.                           |
| extraInfo | string | No   | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.|

**Return value**

| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.addAccount("LiSi", "token101").then(()=> { 
    console.log('addAccount Success');
  }).catch((err) => {
    console.log("addAccount err: "  + JSON.stringify(err));
  });
  ```

### addAccountImplicitly<sup>(deprecated)</sup>

addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

Adds an app account implicitly based on the specified owner. This API uses an asynchronous callback to return the result.

> **NOTE** 
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                   | Mandatory  | Description                     |
| -------- | --------------------- | ---- | ----------------------- |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app.         |
| authType | string                | Yes   | Authentication type. The authentication type is customized. |
| options  | {[key: string]: any}  | Yes   | Authentication options, which can be set as required.|
| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes   | Authenticator callback invoked to return the result.        |

**Example**

  ```js
A
Annie_wang 已提交
2830

A
Annie_wang 已提交
2831 2832 2833 2834 2835 2836 2837

  function onResultCallback(code, result) {
    console.log("resultCode: "  + code);
    console.log("result: "  + JSON.stringify(result));
  }

  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
2838 2839 2840 2841 2842 2843 2844 2845 2846
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
A
Annie_wang 已提交
2847
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
2848
    })
A
Annie_wang 已提交
2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872
  }

  appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
    onResult: onResultCallback,
    onRequestRedirected: onRequestRedirectedCallback
  });
  ```

### deleteAccount<sup>(deprecated)</sup>

deleteAccount(name: string, callback: AsyncCallback&lt;void&gt;): void

Deletes an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                       | Mandatory  | Description              |
| -------- | ------------------------- | ---- | ---------------- |
A
Annie_wang 已提交
2873
| name     | string                    | Yes   | Name of the app account to delete.     |
A
Annie_wang 已提交
2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.deleteAccount("ZhaoLiu", (err) => { 
      console.log("deleteAccount err: " + JSON.stringify(err));
   });
  ```

### deleteAccount<sup>(deprecated)</sup>

deleteAccount(name: string): Promise&lt;void&gt;

Deletes an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
A
Annie_wang 已提交
2900
| name | string | Yes   | Name of the app account to delete.|
A
Annie_wang 已提交
2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.deleteAccount("ZhaoLiu").then(() => { 
        console.log('deleteAccount Success');
   }).catch((err) => {
      console.log("deleteAccount err: "  + JSON.stringify(err));
  });
  ```
### disableAppAccess<sup>(deprecated)</sup>

disableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void

Disables an app account from accessing an app. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| bundleName | string                    | Yes   | Bundle name of the app.                        |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { 
      console.log("disableAppAccess err: " + JSON.stringify(err));
  });
  ```

### disableAppAccess<sup>(deprecated)</sup>

disableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;

Disables an app account from accessing an app. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name       | Type    | Mandatory  | Description              |
| ---------- | ------ | ---- | ---------------- |
| name       | string | Yes   | Name of the target app account.|
| bundleName | string | Yes   | Bundle name of the app.       |

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { 
      console.log('disableAppAccess Success');
  }).catch((err) => {
      console.log("disableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### enableAppAccess<sup>(deprecated)</sup>

enableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void

Enables an app account to access an app. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                          |
| bundleName | string                    | Yes   | Bundle name of the app.                        |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { 
      console.log("enableAppAccess: " + JSON.stringify(err));
   });
  ```

### enableAppAccess<sup>(deprecated)</sup>

enableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;

Enables an app account to access an app. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name       | Type    | Mandatory  | Description       |
| ---------- | ------ | ---- | --------- |
| name       | string | Yes   | Name of the target app account.  |
| bundleName | string | Yes   | Bundle name of the app.|

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { 
       console.log('enableAppAccess Success');
  }).catch((err) => {
      console.log("enableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### checkAppAccountSyncEnable<sup>(deprecated)</sup>

checkAppAccountSyncEnable(name: string, callback: AsyncCallback&lt;boolean&gt;): void

Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9).

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                          | Mandatory  | Description                   |
| -------- | ---------------------------- | ---- | --------------------- |
| name     | string                       | Yes   | Name of the target app account.              |
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.|

**Example**

  ```js
  appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { 
      console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
      console.log('checkAppAccountSyncEnable result: ' + result);
  });
  ```

### checkAppAccountSyncEnable<sup>(deprecated)</sup>

checkAppAccountSyncEnable(name: string): Promise&lt;boolean&gt;

Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9-1).

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|

**Return value**

| Type                    | Description                   |
| ---------------------- | --------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.|

**Example**

  ```js
  appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { 
      console.log('checkAppAccountSyncEnable, result: ' + data);
  }).catch((err) => {
      console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAccountCredential<sup>(deprecated)</sup>

setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void

Set credentials for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name           | Type                       | Mandatory  | Description           |
| -------------- | ------------------------- | ---- | ------------- |
| name           | string                    | Yes   | Name of the target app account.    |
A
Annie_wang 已提交
3126
| credentialType | string                    | Yes   | Type of the credential to set.    |
A
Annie_wang 已提交
3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154
| credential     | string                    | Yes   | Credential value.     |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { 
      console.log("setAccountCredential err: " + JSON.stringify(err));
  });
  ```

### setAccountCredential<sup>(deprecated)</sup>

setAccountCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;

Set credentials for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.  |
A
Annie_wang 已提交
3155
| credentialType | string | Yes   | Type of the credential to set.|
A
Annie_wang 已提交
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516
| credential     | string | Yes   | Credential value.|

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { 
      console.log('setAccountCredential Success');
  }).catch((err) => {
      console.log("setAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo<sup>(deprecated)</sup>

setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void

Sets additional information for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9).


**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type                       | Mandatory  | Description             |
| --------- | ------------------------- | ---- | --------------- |
| name      | string                    | Yes   | Name of the target app account.        |
| extraInfo | string                    | Yes   | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.      |
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { 
      console.log("setAccountExtraInfo err: " + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo<sup>(deprecated)</sup>

setAccountExtraInfo(name: string, extraInfo: string): Promise&lt;void&gt;

Sets additional information for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1).


**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name      | Type    | Mandatory  | Description       |
| --------- | ------ | ---- | --------- |
| name      | string | Yes   | Name of the target app account.  |
| extraInfo | string | Yes   | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.|

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { 
      console.log('setAccountExtraInfo Success');
  }).catch((err) => {
      console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable<sup>(deprecated)</sup>

setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void

Sets data synchronization for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9).

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                       | Mandatory  | Description                       |
| -------- | ------------------------- | ---- | ------------------------- |
| name     | string                    | Yes   | Name of the target app account.                 |
| isEnable | boolean                   | Yes   | Whether to enable data synchronization.              |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { 
      console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable<sup>(deprecated)</sup>

setAppAccountSyncEnable(name: string, isEnable: boolean): Promise&lt;void&gt;

Sets data synchronization for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9-1).

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type     | Mandatory  | Description         |
| -------- | ------- | ---- | ----------- |
| name     | string  | Yes   | Name of the target app account.    |
| isEnable | boolean | Yes   | Whether to enable data synchronization.|

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { 
      console.log('setAppAccountSyncEnable Success');
  }).catch((err) => {
      console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAssociatedData<sup>(deprecated)</sup>

setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void

Sets data to be associated with an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9).


**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                       | Mandatory  | Description               |
| -------- | ------------------------- | ---- | ----------------- |
| name     | string                    | Yes   | Name of the target app account.          |
| key      | string                    | Yes   | Key of the data to set.|
| value    | string                    | Yes   | Value of the data to set.        |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => { 
      console.log("setAssociatedData err: " + JSON.stringify(err));
  });
  ```

### setAssociatedData<sup>(deprecated)</sup>

setAssociatedData(name: string, key: string, value: string): Promise&lt;void&gt;

Sets data to be associated with an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1).


**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name  | Type    | Mandatory  | Description               |
| ----- | ------ | ---- | ----------------- |
| name  | string | Yes   | Name of the target app account.          |
| key      | string | Yes   | Key of the data to set.|
| value    | string | Yes   | Value of the data to set.|

**Return value**

| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

  ```js
  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { 
      console.log('setAssociatedData Success');
  }).catch((err) => {
      console.log("setAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### getAllAccessibleAccounts<sup>(deprecated)</sup>

getAllAccessibleAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void

Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9).

**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.getAllAccessibleAccounts((err, data)=>{
  	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
  	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
  });
  ```

### getAllAccessibleAccounts<sup>(deprecated)</sup>

getAllAccessibleAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Obtains information about all accessible app accounts. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9-1).

**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS

**System capability**: SystemCapability.Account.AppAccount

**Return value**

| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise used to return the accessible app accounts.|

**Example**

  ```js
  appAccountManager.getAllAccessibleAccounts().then((data) => { 
       console.log('getAllAccessibleAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
  });
  ```

### getAllAccounts<sup>(deprecated)</sup>

getAllAccounts(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void

Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9).

**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.   |
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|

**Example**

  ```js
  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<sup>(deprecated)</sup>

getAllAccounts(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9-1).

**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name  | Type    | Mandatory  | Description    |
| ----- | ------ | ---- | ------ |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|

**Return value**

| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise use to return the app accounts that can be accessed by the invoker.|

**Example**

  ```js
  const selfBundle = "com.example.actsgetallaaccounts";
  appAccountManager.getAllAccounts(selfBundle).then((data) => { 
       console.log('getAllAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccounts err: "  + JSON.stringify(err));
  });
  ```

### getAccountCredential<sup>(deprecated)</sup>

getAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void

Obtains the credential of an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name           | Type                         | Mandatory  | Description            |
| -------------- | --------------------------- | ---- | -------------- |
| name           | string                      | Yes   | Name of the target app account.       |
A
Annie_wang 已提交
3517
| credentialType | string                      | Yes   | Type of the credential to obtain.|
A
Annie_wang 已提交
3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545
| callback       | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { 
      console.log("getAccountCredential err: " + JSON.stringify(err));
      console.log('getAccountCredential result: ' + result);
  });
  ```

### getAccountCredential<sup>(deprecated)</sup>

getAccountCredential(name: string, credentialType: string): Promise&lt;string&gt;

Obtains the credential of an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.   |
A
Annie_wang 已提交
3546
| credentialType | string | Yes   | Type of the credential to obtain.|
A
Annie_wang 已提交
3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725

**Return value**

| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the credential obtained.|

**Example**

  ```js
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { 
      console.log('getAccountCredential, result: ' + data);
  }).catch((err) => {
      console.log("getAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### getAccountExtraInfo<sup>(deprecated)</sup>

getAccountExtraInfo(name: string, callback: AsyncCallback&lt;string&gt;): void

Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
| name     | string                      | Yes   | Name of the target app account.        |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the additional information obtained. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { 
      console.log("getAccountExtraInfo err: " + JSON.stringify(err));
      console.log('getAccountExtraInfo result: ' + result);
  });
  ```

### getAccountExtraInfo<sup>(deprecated)</sup>

getAccountExtraInfo(name: string): Promise&lt;string&gt;

Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|

**Return value**

| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the additional information obtained.|

**Example**

  ```js
  appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { 
      console.log('getAccountExtraInfo, result: ' + data);
  }).catch((err) => {
      console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### getAssociatedData<sup>(deprecated)</sup>

getAssociatedData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void

Obtains data associated with an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                         | Mandatory  | Description               |
| -------- | --------------------------- | ---- | ----------------- |
| name     | string                      | Yes   | Name of the target app account.          |
| key      | string                      | Yes   | Key of the data to obtain.        |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the data obtained. Otherwise, **err** is an error object.|

**Example**

  ```js
  appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { 
      console.log("getAssociatedData err: " + JSON.stringify(err));
      console.log('getAssociatedData result: ' + result);
  });
  ```

### getAssociatedData<sup>(deprecated)</sup>

getAssociatedData(name: string, key: string): Promise&lt;string&gt;

Obtains data associated with an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name | Type    | Mandatory  | Description       |
| ---- | ------ | ---- | --------- |
| name | string | Yes   | Name of the target app account.  |
| key  | string | Yes   | Key of the data to obtain.|

**Return value**

| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the data obtained.|

**Example**

  ```js
  appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { 
       console.log('getAssociatedData: ' + data);
  }).catch((err) => {
      console.log("getAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### on('change')<sup>(deprecated)</sup>

on(type: 'change', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void

Subscribes to account information changes of apps.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('accountChange')](#onaccountchange9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                                      | Mandatory  | Description                            |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| type     | 'change'                                 | Yes   | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes.|
| owners   | Array&lt;string&gt;                      | Yes   | App bundle names of the account.                     |
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the account changes.          |

**Example**

  ```js
  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')<sup>(deprecated)</sup>

A
Annie_wang 已提交
3726
off(type: 'change', callback?: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
Annie_wang 已提交
3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740

Unsubscribes from account information changes.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('accountChange')](#offaccountchange9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                              | Mandatory  | Description          |
| -------- | -------------------------------- | ---- | ------------ |
| type     | 'change'                         | Yes   | Event type to unsubscribe from. The value is **'change'**, which indicates the account change event.    |
A
Annie_wang 已提交
3741
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | No   | Callback to unregister.|
A
Annie_wang 已提交
3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790

**Example**

  ```js
  function changeOnCallback(data){
  	console.debug("receive change data:" + JSON.stringify(data));
  	appAccountManager.off('change', function(){
  		console.debug("off finish");
  	})
  }
  try{
  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  }
  catch(err){
  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  }
  ```

### authenticate<sup>(deprecated)</sup>

authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

Authenticates an app account with customized options. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9).

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
| name     | string                | Yes   | Name of the target app account.    |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                | Yes   | Authentication type.          |
| options  | {[key: string]: any}  | Yes   | Options for the authentication.      |
| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes   | Callback invoked to return the result.|

**Example**

  ```js
  function onResultCallback(code, result) {
      console.log("resultCode: "  + code);
      console.log("result: "  + JSON.stringify(result));
  }

  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801
    let wantInfo = {
      deviceId: '',
      bundleName: 'com.example.accountjsdemo',
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.default'],
    }
    this.context.startAbility(wantInfo).then(() => {
      console.log("startAbility successfully");
    }).catch((err) => {
      console.log("startAbility err: " + JSON.stringify(err));
    })
A
Annie_wang 已提交
3802 3803 3804 3805 3806
  }

  appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
    onResult: onResultCallback,
    onRequestRedirected: onRequestRedirectedCallback
A
annie_wangli 已提交
3807 3808 3809
  });
  ```

A
Annie_wang 已提交
3810
### getOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3811

A
Annie_wang 已提交
3812
getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
3813

A
Annie_wang 已提交
3814 3815 3816 3817 3818
Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9).
A
annie_wangli 已提交
3819

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

A
annie_wangli 已提交
3822
**Parameters**
A
annie_wangli 已提交
3823

A
Annie_wang 已提交
3824 3825 3826 3827 3828 3829
| Name     | Type                         | Mandatory  | Description         |
| -------- | --------------------------- | ---- | ----------- |
| name     | string                      | Yes   | Name of the target app account.   |
| owner    | string                      | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string                      | Yes   | Authentication type.      |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object.  |
A
annie_wangli 已提交
3830 3831

**Example**
A
annie_wangli 已提交
3832

Z
zhangalong 已提交
3833
  ```js
A
Annie_wang 已提交
3834 3835 3836
  appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, data) => {
       console.log('getOAuthToken err: ' + JSON.stringify(err));
       console.log('getOAuthToken token: ' + data);
A
annie_wangli 已提交
3837 3838 3839
  });
  ```

A
Annie_wang 已提交
3840
### getOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3841

A
Annie_wang 已提交
3842
getOAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
3843

A
Annie_wang 已提交
3844 3845 3846 3847 3848
Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9-1).
A
annie_wangli 已提交
3849

A
annie_wangli 已提交
3850 3851 3852
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3853

A
Annie_wang 已提交
3854 3855 3856 3857 3858
| Name     | Type    | Mandatory  | Description         |
| -------- | ------ | ---- | ----------- |
| name     | string | Yes   | Name of the target app account.   |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string | Yes   | Authentication type.      |
A
annie_wangli 已提交
3859

A
Annie_wang 已提交
3860
**Return value**
A
annie_wangli 已提交
3861

A
Annie_wang 已提交
3862 3863 3864
| Type                   | Description                   |
| --------------------- | --------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
3865

A
annie_wangli 已提交
3866
**Example**
A
annie_wangli 已提交
3867

Z
zhangalong 已提交
3868
  ```js
A
Annie_wang 已提交
3869 3870
  appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => {
       console.log('getOAuthToken token: ' + data);
A
annie_wangli 已提交
3871
  }).catch((err) => {
A
Annie_wang 已提交
3872
      console.log("getOAuthToken err: "  + JSON.stringify(err));
A
annie_wangli 已提交
3873 3874 3875
  });
  ```

A
Annie_wang 已提交
3876
### setOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3877

A
Annie_wang 已提交
3878
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
3879

A
Annie_wang 已提交
3880 3881 3882 3883 3884
Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9).
A
annie_wangli 已提交
3885

A
annie_wangli 已提交
3886 3887 3888
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3889

A
Annie_wang 已提交
3890 3891 3892 3893 3894 3895
| Name     | Type                       | Mandatory  | Description      |
| -------- | ------------------------- | ---- | -------- |
| name     | string                    | Yes   | Name of the target app account.|
| authType | string                    | Yes   | Authentication type.   |
| token    | string                    | Yes   | Token to set.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
A
annie_wangli 已提交
3896

A
annie_wangli 已提交
3897
**Example**
A
annie_wangli 已提交
3898

Z
zhangalong 已提交
3899
  ```js
A
Annie_wang 已提交
3900 3901
  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3902 3903 3904
  });
  ```

A
Annie_wang 已提交
3905
### setOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3906

A
Annie_wang 已提交
3907
setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
3908

A
Annie_wang 已提交
3909 3910 3911 3912 3913
Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9-1).
A
annie_wangli 已提交
3914

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

A
annie_wangli 已提交
3917
**Parameters**
A
annie_wangli 已提交
3918

A
Annie_wang 已提交
3919 3920 3921 3922 3923
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| name     | string | Yes   | Name of the target app account.|
| authType | string | Yes   | Authentication type.   |
| token    | string | Yes   | Authorization token to set.|
A
annie_wangli 已提交
3924

A
Annie_wang 已提交
3925
**Return value**
A
annie_wangli 已提交
3926

A
Annie_wang 已提交
3927 3928 3929
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
3930 3931

**Example**
A
annie_wangli 已提交
3932

Z
zhangalong 已提交
3933
  ```js
A
Annie_wang 已提交
3934 3935
  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
      console.log('setOAuthToken successfully');
A
annie_wangli 已提交
3936
  }).catch((err) => {
A
Annie_wang 已提交
3937
      console.log('setOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3938 3939 3940
  });
  ```

A
Annie_wang 已提交
3941
### deleteOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3942

A
Annie_wang 已提交
3943 3944 3945
deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void

Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
3946

A
Annie_wang 已提交
3947 3948 3949
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9).
A
annie_wangli 已提交
3950

A
annie_wangli 已提交
3951 3952 3953
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3954

A
Annie_wang 已提交
3955 3956 3957 3958 3959 3960 3961
| Name     | Type                       | Mandatory  | Description          |
| -------- | ------------------------- | ---- | ------------ |
| name     | string                    | Yes   | Name of the target app account.    |
| owner    | string                    | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                    | Yes   | Authentication type.       |
| token    | string                    | Yes   | Authorization token to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.    |
A
annie_wangli 已提交
3962

A
annie_wangli 已提交
3963
**Example**
A
annie_wangli 已提交
3964

Z
zhangalong 已提交
3965
  ```js
A
Annie_wang 已提交
3966 3967
  appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3968 3969 3970
  });
  ```

A
Annie_wang 已提交
3971
### deleteOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3972

A
Annie_wang 已提交
3973 3974 3975
deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;

Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
3976

A
Annie_wang 已提交
3977 3978 3979
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9-1).
A
annie_wangli 已提交
3980

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

A
annie_wangli 已提交
3983
**Parameters**
A
annie_wangli 已提交
3984

A
Annie_wang 已提交
3985 3986 3987 3988 3989 3990
| Name     | Type    | Mandatory  | Description          |
| -------- | ------ | ---- | ------------ |
| name     | string | Yes   | Name of the target app account.    |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string | Yes   | Authentication type.       |
| token    | string | Yes   | Authorization token to delete.|
A
annie_wangli 已提交
3991

A
Annie_wang 已提交
3992
**Return value**
A
annie_wangli 已提交
3993

A
Annie_wang 已提交
3994 3995 3996
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
3997 3998

**Example**
A
annie_wangli 已提交
3999

Z
zhangalong 已提交
4000
  ```js
A
Annie_wang 已提交
4001 4002
  appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
       console.log('deleteOAuthToken successfully');
A
annie_wangli 已提交
4003
  }).catch((err) => {
A
Annie_wang 已提交
4004
      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
A
annie_wangli 已提交
4005 4006 4007
  });
  ```

A
Annie_wang 已提交
4008
### setOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4009

A
Annie_wang 已提交
4010 4011 4012
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void

Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4013

A
Annie_wang 已提交
4014 4015 4016
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9).
A
Annie_wang 已提交
4017 4018 4019 4020 4021

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4022 4023 4024 4025 4026 4027 4028
| Name       | Type                       | Mandatory  | Description                       |
| ---------- | ------------------------- | ---- | ------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| authType   | string                    | Yes   | Authentication type.                    |
| bundleName | string                    | Yes   | Bundle name of the app.             |
| isVisible  | boolean                   | Yes   | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.                 |
A
Annie_wang 已提交
4029 4030 4031 4032

**Example**

  ```js
A
Annie_wang 已提交
4033 4034
  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4035 4036 4037
  });
  ```

A
Annie_wang 已提交
4038
### setOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4039

A
Annie_wang 已提交
4040 4041 4042
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;

Sets the visibility of an authorization token to an app. This API uses a promise to return the result.
A
Annie_wang 已提交
4043

A
Annie_wang 已提交
4044 4045 4046
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9-1).
A
Annie_wang 已提交
4047 4048 4049 4050 4051

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4052 4053 4054 4055 4056 4057
| Name       | Type     | Mandatory  | Description          |
| ---------- | ------- | ---- | ------------ |
| name       | string  | Yes   | Name of the target app account.    |
| authType   | string  | Yes   | Authentication type.       |
| bundleName | string  | Yes   | Bundle name of the app.|
| isVisible  | boolean | Yes   | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.       |
A
Annie_wang 已提交
4058

A
Annie_wang 已提交
4059
**Return value**
A
Annie_wang 已提交
4060

A
Annie_wang 已提交
4061 4062 4063
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
Annie_wang 已提交
4064 4065 4066 4067

**Example**

  ```js
A
Annie_wang 已提交
4068 4069
  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
      console.log('setOAuthTokenVisibility successfully');
A
Annie_wang 已提交
4070
  }).catch((err) => {
A
Annie_wang 已提交
4071
      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4072 4073 4074
  });
  ```

A
Annie_wang 已提交
4075
### checkOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4076

A
Annie_wang 已提交
4077 4078 4079
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void

Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4080

A
Annie_wang 已提交
4081 4082 4083
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9).
A
Annie_wang 已提交
4084 4085 4086 4087 4088

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4089 4090 4091 4092 4093 4094
| Name       | Type                          | Mandatory  | Description         |
| ---------- | ---------------------------- | ---- | ----------- |
| name       | string                       | Yes   | Name of the target app account.   |
| 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. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object.   |
A
Annie_wang 已提交
4095 4096 4097 4098

**Example**

  ```js
A
Annie_wang 已提交
4099 4100 4101
  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
A
Annie_wang 已提交
4102 4103 4104
  });
  ```

A
Annie_wang 已提交
4105 4106 4107
### checkOAuthTokenVisibility<sup>(deprecated)</sup>

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
A
Annie_wang 已提交
4108

A
Annie_wang 已提交
4109
Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result.
A
Annie_wang 已提交
4110

A
Annie_wang 已提交
4111 4112 4113
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9-1).
A
Annie_wang 已提交
4114 4115 4116 4117 4118

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4119 4120 4121 4122 4123
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
| name       | string | Yes   | Name of the target app account.     |
| authType   | string | Yes   | Authentication type.        |
| bundleName | string | Yes   | Bundle name of the app.|
A
Annie_wang 已提交
4124

A
Annie_wang 已提交
4125
**Return value**
A
Annie_wang 已提交
4126

A
Annie_wang 已提交
4127 4128 4129
| Type                    | Description                   |
| ---------------------- | --------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.|
A
Annie_wang 已提交
4130 4131 4132 4133

**Example**

  ```js
A
Annie_wang 已提交
4134 4135
  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => {
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
A
Annie_wang 已提交
4136
  }).catch((err) => {
A
Annie_wang 已提交
4137
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4138 4139 4140
  });
  ```

A
Annie_wang 已提交
4141
### getAllOAuthTokens<sup>(deprecated)</sup>
A
Annie_wang 已提交
4142

A
Annie_wang 已提交
4143 4144 4145
getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt;): void

Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4146

A
Annie_wang 已提交
4147 4148 4149
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9).
A
Annie_wang 已提交
4150 4151 4152 4153 4154

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4155 4156 4157 4158 4159
| Name     | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| name     | string                                   | Yes   | Name of the target app account.   |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.|
| callback | AsyncCallback&lt;Array&lt;[OAuthTokenInfo](#oauthtokeninfodeprecated)&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object.   |
A
Annie_wang 已提交
4160 4161 4162 4163

**Example**

  ```js
A
Annie_wang 已提交
4164 4165 4166
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo", (err, data) => {
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4167 4168 4169
  });
  ```

A
Annie_wang 已提交
4170
### getAllOAuthTokens<sup>(deprecated)</sup>
A
Annie_wang 已提交
4171

A
Annie_wang 已提交
4172
getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
A
Annie_wang 已提交
4173

A
Annie_wang 已提交
4174 4175 4176 4177 4178
Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9-1).
A
Annie_wang 已提交
4179 4180 4181 4182 4183

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4184 4185 4186 4187
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| name  | string | Yes   | Name of the target app account.   |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
4188

A
Annie_wang 已提交
4189
**Return value**
A
Annie_wang 已提交
4190

A
Annie_wang 已提交
4191 4192 4193
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt; [OAuthTokenInfo](#oauthtokeninfodeprecated)&gt;&gt; | Promise used to return the tokens obtained.|
A
Annie_wang 已提交
4194 4195 4196 4197

**Example**

  ```js
A
Annie_wang 已提交
4198 4199
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => {
      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4200
  }).catch((err) => {
A
Annie_wang 已提交
4201
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4202 4203 4204
  });
  ```

A
Annie_wang 已提交
4205 4206 4207
### getOAuthList<sup>(deprecated)</sup>

getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
Annie_wang 已提交
4208

A
Annie_wang 已提交
4209
Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4210

A
Annie_wang 已提交
4211 4212 4213
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9).
A
Annie_wang 已提交
4214 4215 4216 4217 4218

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4219 4220 4221 4222 4223
| Name     | Type                                      | Mandatory  | Description                     |
| -------- | ---------------------------------------- | ---- | ----------------------- |
| name     | string                                   | Yes   | Name of the target app account.               |
| authType | string                                   | Yes   | Authentication type.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object.              |
A
Annie_wang 已提交
4224 4225 4226 4227

**Example**

  ```js
A
Annie_wang 已提交
4228 4229 4230
  appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData", (err, data) => {
    console.log('getOAuthList err: ' + JSON.stringify(err));
    console.log('getOAuthList data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4231 4232 4233
  });
  ```

A
Annie_wang 已提交
4234
### getOAuthList<sup>(deprecated)</sup>
A
Annie_wang 已提交
4235

A
Annie_wang 已提交
4236
getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
A
Annie_wang 已提交
4237

A
Annie_wang 已提交
4238 4239 4240 4241 4242
Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9-1).
A
Annie_wang 已提交
4243 4244 4245 4246 4247

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4248 4249 4250 4251
| Name     | Type    | Mandatory  | Description                     |
| -------- | ------ | ---- | ----------------------- |
| name     | string | Yes   | Name of the target app account.               |
| authType | string | Yes   | Authentication type.|
A
Annie_wang 已提交
4252

A
Annie_wang 已提交
4253
**Return value**
A
Annie_wang 已提交
4254

A
Annie_wang 已提交
4255 4256 4257
| Type                                | Description                   |
| ---------------------------------- | --------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return a list of authorized bundles.|
A
Annie_wang 已提交
4258 4259 4260 4261

**Example**

  ```js
A
Annie_wang 已提交
4262 4263
  appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => {
       console.log('getOAuthList data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4264
  }).catch((err) => {
A
Annie_wang 已提交
4265
      console.log("getOAuthList err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4266 4267 4268
  });
  ```

A
Annie_wang 已提交
4269
### getAuthenticatorCallback<sup>(deprecated)</sup>
A
Annie_wang 已提交
4270

A
Annie_wang 已提交
4271
getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
A
Annie_wang 已提交
4272

A
Annie_wang 已提交
4273 4274 4275 4276 4277
Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9).
A
Annie_wang 已提交
4278 4279 4280 4281 4282

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4283 4284 4285 4286
| Name      | Type                                      | Mandatory  | Description      |
| --------- | ---------------------------------------- | ---- | -------- |
| sessionId | string                                   | Yes   | ID of the authentication session.|
| callback  | AsyncCallback&lt;[AuthenticatorCallback](#authenticatorcallbackdeprecated)&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback obtained. Otherwise, **err** is an error object.|
A
Annie_wang 已提交
4287 4288 4289 4290

**Example**

  ```js
A
Annie_wang 已提交
4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304
  import featureAbility from '@ohos.ability.featureAbility';
  featureAbility.getWant((err, want) => {
    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
    appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
        if (err.code != account_appAccount.ResultCode.SUCCESS) {
            console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
            return;
        }
        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                      [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    });
A
Annie_wang 已提交
4305 4306 4307
  });
  ```

A
Annie_wang 已提交
4308
### getAuthenticatorCallback<sup>(deprecated)</sup>
A
Annie_wang 已提交
4309

A
Annie_wang 已提交
4310
getAuthenticatorCallback(sessionId: string): Promise&lt;AuthenticatorCallback&gt;
A
Annie_wang 已提交
4311

A
Annie_wang 已提交
4312 4313 4314 4315 4316
Obtains the authenticator callback for an authentication session. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9-1).
A
Annie_wang 已提交
4317 4318 4319 4320 4321

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4322 4323 4324 4325 4326 4327 4328 4329 4330
| Name      | Type    | Mandatory  | Description      |
| --------- | ------ | ---- | -------- |
| sessionId | string | Yes   | ID of the authentication session.|

**Return value**

| Type                                  | Description                   |
| ------------------------------------ | --------------------- |
| Promise&lt;[AuthenticatorCallback](#authenticatorcallbackdeprecated)&gt; | Promise used to return the authenticator callback obtained.|
A
Annie_wang 已提交
4331 4332 4333 4334

**Example**

  ```js
A
Annie_wang 已提交
4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349
  import featureAbility from '@ohos.ability.featureAbility';

  featureAbility.getWant().then((want) => {
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
          var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                        [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
      }).catch((err) => {
          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
      });
  }).catch((err) => {
      console.log("getWant err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4350 4351 4352
  });
  ```

A
Annie_wang 已提交
4353 4354 4355
### getAuthenticatorInfo<sup>(deprecated)</sup>

getAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void
A
Annie_wang 已提交
4356

A
Annie_wang 已提交
4357
Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4358

A
Annie_wang 已提交
4359 4360 4361
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9).
A
Annie_wang 已提交
4362 4363 4364 4365 4366

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4367 4368 4369 4370
| Name     | Type                                    | Mandatory  | Description         |
| -------- | -------------------------------------- | ---- | ----------- |
| owner    | string                                 | Yes   | Owner of the app account. The value is the bundle name of the app.|
| callback | AsyncCallback&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object.   |
A
Annie_wang 已提交
4371 4372 4373 4374

**Example**

  ```js
A
Annie_wang 已提交
4375 4376 4377
  appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo", (err, data) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
      console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4378 4379 4380
  });
  ```

A
Annie_wang 已提交
4381 4382 4383
### getAuthenticatorInfo<sup>(deprecated)</sup>

getAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;
A
Annie_wang 已提交
4384

A
Annie_wang 已提交
4385
Obtains the authenticator information of an app. This API uses a promise to return the result.
A
Annie_wang 已提交
4386

A
Annie_wang 已提交
4387 4388 4389
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9-1).
A
Annie_wang 已提交
4390 4391 4392 4393 4394

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

A
Annie_wang 已提交
4395 4396 4397 4398 4399 4400 4401 4402 4403
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|

**Return value**

| Type                              | Description                   |
| -------------------------------- | --------------------- |
| Promise&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Promise used to return the authenticator information obtained.|
A
Annie_wang 已提交
4404 4405 4406 4407

**Example**

  ```js
A
Annie_wang 已提交
4408 4409 4410 4411
  appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo").then((data) => { 
       console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4412 4413 4414
  });
  ```

A
annie_wangli 已提交
4415 4416
## AppAccountInfo

A
annie_wangli 已提交
4417 4418
Defines app account information.

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

A
Annie_wang 已提交
4421 4422 4423
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438
| name  | string | Yes   | Name of the target app account.   |

## AuthTokenInfo<sup>9+</sup>

Defines authorization token information.

**System capability**: SystemCapability.Account.AppAccount

| Name              | Type           | Mandatory | Description             |
| -------------------- | -------------- | ----- | ---------------- |
| authType<sup>9+</sup>             | string         | Yes   | Authentication type.  |
| token<sup>9+</sup>                | string         | Yes   | Value of the authorization token.      |
| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No   | Account information of the authorization token.|

## OAuthTokenInfo<sup>(deprecated)</sup>
A
annie_wangli 已提交
4439

A
Annie_wang 已提交
4440
Defines authorization token information.
A
annie_wangli 已提交
4441

A
Annie_wang 已提交
4442 4443 4444
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthTokenInfo](#authtokeninfo9).
A
annie_wangli 已提交
4445

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

A
Annie_wang 已提交
4448 4449 4450
| Name              | Type           | Mandatory | Description             |
| -------------------- | -------------- | ----- | ---------------- |
| authType             | string         | Yes   | Authentication type.  |
A
Annie_wang 已提交
4451 4452
| token                | string         | Yes   | Value of the authorization token.      |
| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No   | Account information of the authorization token.|
A
annie_wangli 已提交
4453 4454 4455 4456 4457

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

Defines OAuth authenticator information.

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

A
Annie_wang 已提交
4460 4461 4462
| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| owner   | string | Yes   | Owner of the authenticator. The value is the bundle name of the app.|
A
Annie_wang 已提交
4463 4464
| iconId  | number | Yes   | ID of the authenticator icon. |
| labelId | number | Yes   | ID of the authenticator label. |
A
Annie_wang 已提交
4465

A
Annie_wang 已提交
4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497
## AuthResult<sup>9+</sup>

Defines the authentication result.

**System capability**: SystemCapability.Account.AppAccount

| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| account   | [AppAccountInfo](#appaccountinfo) | No   | Account information of the authorization token.|
| tokenInfo  | [AuthTokenInfo](#authtokeninfo9) | No   | Token information. |

## CreateAccountOptions<sup>9+</sup>

Defines the options for creating an app account.

**System capability**: SystemCapability.Account.AppAccount

| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| customData   | {[key: string]: string} | No   | Custom data.|

## CreateAccountImplicitlyOptions<sup>9+</sup>

Defines the options for implicitly creating an app account.

**System capability**: SystemCapability.Account.AppAccount

| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| requiredLabels   | Array&lt;string&gt; | No   | Labels required.|
| authType   | string | No   | Authentication type.|
| parameters   | {[key: string]: Object} | No   | Customized parameters.|
A
Annie_wang 已提交
4498 4499
## SelectAccountsOptions<sup>9+</sup>

A
Annie_wang 已提交
4500
Defines the options for selecting accounts.
A
Annie_wang 已提交
4501 4502 4503 4504 4505

**System capability**: SystemCapability.Account.AppAccount

| Name         | Type                        | Mandatory | Description               |
| --------------- | --------------------------- | ----- | ------------------- |
A
Annie_wang 已提交
4506
| allowedAccounts | Array&lt;[AppAccountInfo](#appaccountinfo)&gt; | No   | Allowed accounts.     |
A
Annie_wang 已提交
4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519
| allowedOwners   | Array&lt;string&gt;         | No   | Allowed account owners.|
| requiredLabels  | Array&lt;string&gt;         | No   | Labels required for the authenticator.   |

## VerifyCredentialOptions<sup>9+</sup>

Represents the options for verifying the user credential.

**System capability**: SystemCapability.Account.AppAccount

| Name         | Type                  | Mandatory | Description          |
| -------------- | ---------------------- | ----- | -------------- |
| credentialType | string                 | No   | Type of the credential to verify.     |
| credential     | string                 | No   | Credential value.     |
A
Annie_wang 已提交
4520
| parameters     | {[key: string]: Object} | No   | Customized parameters.|
A
Annie_wang 已提交
4521 4522 4523 4524 4525 4526 4527 4528 4529 4530


## SetPropertiesOptions<sup>9+</sup>

Represents the options for setting authenticator properties.

**System capability**: SystemCapability.Account.AppAccount

| Name    | Type                   | Mandatory | Description          |
| ---------- | ---------------------- | ----- | -------------- |
A
Annie_wang 已提交
4531 4532
| properties | {[key: string]: Object} | No   | Authenticator properties.     |
| parameters | {[key: string]: Object} | No   | Customized parameters.|
A
annie_wangli 已提交
4533 4534 4535 4536 4537

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

Enumerates the constants.

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

A
Annie_wang 已提交
4540
| Name                           | Value                   | Description                  |
A
Annie_wang 已提交
4541
| -------------------------------- | ---------------------- | ----------------------- |
A
Annie_wang 已提交
4542 4543 4544 4545 4546 4547 4548 4549
| ACTION_ADD_ACCOUNT_IMPLICITLY<sup>(deprecated)</sup>    | "addAccountImplicitly" | Operation of adding an account implicitly. |
| ACTION_AUTHENTICATE<sup>(deprecated)</sup>              | "authenticate"         | Authentication operation.        |
| ACTION_CREATE_ACCOUNT_IMPLICITLY<sup>9+</sup>    | "createAccountImplicitly" | Operation of creating an account implicitly. |
| ACTION_AUTH<sup>9+</sup>              | "auth"         | Authentication operation.        |
| ACTION_VERIFY_CREDENTIAL<sup>9+</sup>    | "verifyCredential" | Operation of verifying credentials. |
| ACTION_SET_AUTHENTICATOR_PROPERTIES<sup>9+</sup> | "setAuthenticatorProperties" | Operation of setting authenticator properties.     |
| KEY_NAME                         | "name"                 | Name of the app account. |
| KEY_OWNER                        | "owner"                | Owner of the app account.|
A
Annie_wang 已提交
4550 4551 4552 4553 4554 4555 4556 4557 4558
| KEY_TOKEN                        | "token"                | Token.        |
| KEY_ACTION                       | "action"               | Operation.        |
| KEY_AUTH_TYPE                    | "authType"             | Authentication type.    |
| KEY_SESSION_ID                   | "sessionId"            | Session ID.    |
| KEY_CALLER_PID                   | "callerPid"            | PID of the caller.   |
| KEY_CALLER_UID                   | "callerUid"            | UID of the caller.   |
| KEY_CALLER_BUNDLE_NAME           | "callerBundleName"     | Bundle name of the caller.   |
| KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels"       | Required labels.   |
| KEY_BOOLEAN_RESULT<sup>9+</sup>  | "booleanResult"        | Return value of the Boolean type.   |
A
annie_wangli 已提交
4559

A
Annie_wang 已提交
4560
## ResultCode<sup>(deprecated)</sup>
A
annie_wangli 已提交
4561 4562 4563

Enumerates the result codes.

A
Annie_wang 已提交
4564 4565
> **NOTE**<br>
> This enum is supported since API version 8 and deprecated since API version 9. Error codes are used from API version 9. For details, see [Account Management Error Codes](../errorcodes/errorcode-account.md).
A
Annie_wang 已提交
4566

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

A
Annie_wang 已提交
4569
| Name                                 | Value  | Description          |
A
Annie_wang 已提交
4570 4571 4572
| ----------------------------------- | ----- | ------------ |
| SUCCESS                             | 0     | The operation is successful.     |
| ERROR_ACCOUNT_NOT_EXIST             | 10001 | The app account does not exist.  |
A
Annie_wang 已提交
4573
| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. |
A
Annie_wang 已提交
4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584
| 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.     |
A
Annie_wang 已提交
4585
| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | The authorization token does not exist.|
A
Annie_wang 已提交
4586 4587 4588 4589
| ERROR_OAUTH_TOKEN_TOO_MANY          | 10015 | The number of OAuth 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 已提交
4590

A
Annie_wang 已提交
4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693
## AuthCallback<sup>9+</sup>

Implements authenticator callbacks.

### onResult<sup>9+</sup>

onResult: (code: number, result?: AuthResult) =&gt; void

Called to return the result of an authentication request.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                  | Mandatory  | Description    |
| ------ | -------------------- | ---- | ------ |
| code   | number               | Yes   | Authentication result code.|
| result | [AuthResult](#authresult9) | No   | Authentication result. |

**Example**

  ```js
  let appAccountManager = account_appAccount.createAppAccountManager();
  var sessionId = "1234";
  appAccountManager.getAuthCallback(sessionId).then((callback) => {
      var result = {
          accountInfo: {
            name: "Lisi",
            owner: "com.example.accountjsdemo",
          },
          tokenInfo: {
            token: "xxxxxx",
            authType: "getSocialData"
          }
      };
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
  }).catch((err) => {
      console.log("getAuthCallback err: "  + JSON.stringify(err));
  });
  ```

### onRequestRedirected<sup>9+</sup>

onRequestRedirected: (request: Want) =&gt; void

Called to redirect a request.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name    | Type  | Mandatory  | Description        |
| ------- | ---- | ---- | ---------- |
| request | Want | Yes   | Request to be redirected.|

**Example**

  ```js
  class MyAuthenticator extends account_appAccount.Authenticator {
      createAccountImplicitly(options, callback) {
          callback.onRequestRedirected({
              bundleName: "com.example.accountjsdemo",
              abilityName: "com.example.accountjsdemo.LoginAbility",
          });
      }

      auth(name, authType, options, callback) {
          var result = {
            accountInfo: {
              name: "Lisi",
              owner: "com.example.accountjsdemo",
            },
            tokenInfo: {
              token: "xxxxxx",
              authType: "getSocialData"
            }
          };
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
      }
  }
  ```

### onRequestContinued<sup>9+</sup>

onRequestContinued?: () =&gt; void

Called to continue to process the request.

**System capability**: SystemCapability.Account.AppAccount

**Example**

  ```js
  let appAccountManager = account_appAccount.createAppAccountManager();
  var sessionId = "1234";
  appAccountManager.getAuthCallback(sessionId).then((callback) => {
      callback.onRequestContinued();
  }).catch((err) => {
      console.log("getAuthCallback err: "  + JSON.stringify(err));
  });
  ```

## AuthenticatorCallback<sup>(deprecated)</sup>
A
annie_wangli 已提交
4694

A
Annie_wang 已提交
4695
Provides OAuth authenticator callbacks.
A
annie_wangli 已提交
4696

A
Annie_wang 已提交
4697 4698 4699 4700
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthCallback](#authcallback9).

A
annie_wangli 已提交
4701 4702
### onResult<sup>8+</sup>

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

A
Annie_wang 已提交
4705
Called to return the result of an authentication request.
A
annie_wangli 已提交
4706

A
annie_wangli 已提交
4707 4708 4709
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4710

A
Annie_wang 已提交
4711 4712 4713 4714
| Name   | Type                  | Mandatory  | Description    |
| ------ | -------------------- | ---- | ------ |
| code   | number               | Yes   | Authentication result code.|
| result | {[key: string]: any} | Yes   | Authentication result. |
A
annie_wangli 已提交
4715

A
annie_wangli 已提交
4716
**Example**
A
annie_wangli 已提交
4717

Z
zhangalong 已提交
4718
  ```js
A
Annie_wang 已提交
4719
  let appAccountManager = account_appAccount.createAppAccountManager();
A
annie_wangli 已提交
4720 4721
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
4722
      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
A
Annie_wang 已提交
4723
                    [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
A
Annie_wang 已提交
4724
                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
A
annie_wangli 已提交
4725
                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
A
Annie_wang 已提交
4726
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
4727 4728 4729 4730 4731 4732 4733
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

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

A
annie_wangli 已提交
4734
onRequestRedirected: (request: Want) =&gt; void
A
annie_wangli 已提交
4735

A
Annie_wang 已提交
4736
Called to redirect a request.
A
annie_wangli 已提交
4737

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

A
annie_wangli 已提交
4740
**Parameters**
A
Annie_wang 已提交
4741

A
Annie_wang 已提交
4742 4743 4744
| Name    | Type  | Mandatory  | Description        |
| ------- | ---- | ---- | ---------- |
| request | Want | Yes   | Request to be redirected.|
A
annie_wangli 已提交
4745 4746

**Example**
A
annie_wangli 已提交
4747

Z
zhangalong 已提交
4748
  ```js
A
annie_wangli 已提交
4749 4750 4751
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
A
Annie_wang 已提交
4752 4753
              bundleName: "com.example.accountjsdemo",
              abilityName: "com.example.accountjsdemo.LoginAbility",
A
annie_wangli 已提交
4754 4755
          });
      }
A
annie_wangli 已提交
4756

A
annie_wangli 已提交
4757
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
4758 4759 4760 4761
          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 已提交
4762 4763 4764 4765
      }
  }
  ```

A
Annie_wang 已提交
4766 4767
### onRequestContinued<sup>9+</sup>

A
Annie_wang 已提交
4768
onRequestContinued?: () =&gt; void
A
Annie_wang 已提交
4769

A
Annie_wang 已提交
4770
Called to continue to process the request.
A
Annie_wang 已提交
4771 4772 4773 4774 4775 4776

**System capability**: SystemCapability.Account.AppAccount

**Example**

  ```js
A
Annie_wang 已提交
4777
  let appAccountManager = account_appAccount.createAppAccountManager();
A
Annie_wang 已提交
4778 4779
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
Annie_wang 已提交
4780
      callback.onRequestContinued();
A
Annie_wang 已提交
4781 4782 4783 4784 4785
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
4786 4787
## Authenticator<sup>8+</sup>

A
Annie_wang 已提交
4788
Provides APIs to operate the authenticator.
A
annie_wangli 已提交
4789

A
Annie_wang 已提交
4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801
### createAccountImplicitly<sup>9+</sup>

createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void

Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4802
| options          | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9)  | Yes   | Options for implicitly creating an account.     |
A
Annie_wang 已提交
4803 4804
| callback         | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|

A
Annie_wang 已提交
4805
### addAccountImplicitly<sup>(deprecated)</sup>
A
annie_wangli 已提交
4806

A
annie_wangli 已提交
4807
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
4808

A
Annie_wang 已提交
4809 4810 4811 4812 4813
Adds an app account implicitly based on the specified authentication type and options. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9-2).
A
annie_wangli 已提交
4814

A
annie_wangli 已提交
4815 4816 4817
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4818

A
Annie_wang 已提交
4819 4820 4821 4822 4823
| 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.     |
A
Annie_wang 已提交
4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842
| callback         | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes   | Authenticator callback invoked to return the authentication result.|

### auth<sup>9+</sup>

auth(name: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void

Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| name             | string                | Yes   | Name of the target app account.       |
| authType         | string                | Yes   | Authentication type.     |
| callerBundleName | string                | Yes   | Authentication type.      |
| options          | {[key: string]: Object}  | Yes   | Options for the authentication.     |
| callback         | [AuthCallback](#authcallback9) | Yes   | Callback invoked to return the result.|
A
annie_wangli 已提交
4843

A
Annie_wang 已提交
4844
### authenticate<sup>(deprecated)</sup>
A
annie_wangli 已提交
4845

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

A
Annie_wang 已提交
4848 4849 4850 4851 4852
Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9-2).
A
annie_wangli 已提交
4853

A
annie_wangli 已提交
4854 4855 4856
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4857

A
Annie_wang 已提交
4858 4859 4860 4861 4862 4863
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| name             | string                | Yes   | Name of the target app account.       |
| authType         | string                | Yes   | Authentication type.     |
| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
A
Annie_wang 已提交
4864
| callback         | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes   | Authenticator callback invoked to return the authentication result.|
A
Annie_wang 已提交
4865 4866 4867

### verifyCredential<sup>9+</sup>

A
Annie_wang 已提交
4868
verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void;
A
Annie_wang 已提交
4869

A
Annie_wang 已提交
4870
Verifies the credential of an app account. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4871 4872 4873 4874

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4875

A
Annie_wang 已提交
4876 4877
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4878
| name      | string                   | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4879
| options   | [VerifyCredentialOptions](#verifycredentialoptions9)  | Yes   | Options for credential verification.           |
A
Annie_wang 已提交
4880
| callback  | [AuthCallback](#authcallback9)    | Yes   | Authenticator callback invoked to return the verification result.|
A
Annie_wang 已提交
4881 4882 4883

### setProperties<sup>9+</sup>

A
Annie_wang 已提交
4884
setProperties(options: SetPropertiesOptions, callback: AuthCallback): void;
A
Annie_wang 已提交
4885

A
Annie_wang 已提交
4886
Sets the authenticator properties. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4887 4888 4889 4890

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4891

A
Annie_wang 已提交
4892 4893 4894
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| options   | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.           |
A
Annie_wang 已提交
4895
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
4896 4897 4898

### checkAccountLabels<sup>9+</sup>

A
Annie_wang 已提交
4899
checkAccountLabels(name: string, labels: Array&lt;string&gt;, callback: AuthCallback): void;
A
Annie_wang 已提交
4900 4901 4902 4903 4904 4905

Checks the account labels. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4906

A
Annie_wang 已提交
4907 4908
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4909
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4910
| labels    | Array&lt;string&gt;          | Yes   | Labels to check.                  |
A
Annie_wang 已提交
4911
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the check result.|
A
Annie_wang 已提交
4912

A
Annie_wang 已提交
4913
### checkAccountRemovable<sup>9+</sup>
A
Annie_wang 已提交
4914

A
Annie_wang 已提交
4915
checkAccountRemovable(name: string, callback: AuthCallback): void;
A
Annie_wang 已提交
4916 4917 4918 4919 4920 4921

Checks whether an app account can be deleted. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4922

A
Annie_wang 已提交
4923 4924
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4925
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4926
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
4927 4928 4929 4930 4931 4932 4933 4934

### getRemoteObject<sup>9+</sup>

getRemoteObject(): rpc.RemoteObject;

Obtains the remote object of an authenticator. This API cannot be overloaded.

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

A
annie_wangli 已提交
4936
**Example**
A
annie_wangli 已提交
4937

Z
zhangalong 已提交
4938
  ```js
A
annie_wangli 已提交
4939
  class MyAuthenticator extends account_appAccount.Authenticator {
A
Annie_wang 已提交
4940 4941 4942 4943 4944 4945
    addAccountImplicitly(authType, callerBundleName, options, callback) {
      callback.onRequestRedirected({
        bundleName: "com.example.accountjsdemo",
        abilityName: "com.example.accountjsdemo.LoginAbility",
      });
    }
A
annie_wangli 已提交
4946

A
Annie_wang 已提交
4947 4948 4949 4950 4951 4952
    authenticate(name, authType, callerBundleName, options, callback) {
      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_wang 已提交
4953

A
Annie_wang 已提交
4954 4955 4956 4957 4958 4959 4960 4961 4962
    verifyCredential(name, options, callback) {
      callback.onRequestRedirected({
        bundleName: "com.example.accountjsdemo",
        abilityName: "com.example.accountjsdemo.VerifyAbility",
        parameters: {
          name: name
        }
      });
    }
A
Annie_wang 已提交
4963

A
Annie_wang 已提交
4964 4965 4966
    setProperties(options, callback) {
      callback.onResult(account_appAccount.ResultCode.SUCCESS, {});
    }
A
Annie_wang 已提交
4967

A
Annie_wang 已提交
4968 4969 4970 4971 4972
    checkAccountLabels(name, labels, callback) {
      var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false};
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
  
A
Annie_wang 已提交
4973
    checkAccountRemovable(name, callback) {
A
Annie_wang 已提交
4974 4975 4976
      var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true};
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
A
annie_wangli 已提交
4977
  }
A
Annie_wang 已提交
4978
  var authenticator = null;
A
annie_wangli 已提交
4979
  export default {
A
Annie_wang 已提交
4980 4981 4982 4983
    onConnect(want) {
      authenticator = new MyAuthenticator();
      return authenticator.getRemoteObject();
    }
A
annie_wangli 已提交
4984
  }
A
Annie_wang 已提交
4985
  ```