js-apis-appAccount.md 182.6 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
| 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. |
A
annie_wangli 已提交
151

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

Z
zhangalong 已提交
154
  ```js
A
Annie_wang 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168
  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 已提交
169 170
  ```

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

A
Annie_wang 已提交
173 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
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 已提交
206 207 208 209 210 211 212 213 214
    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 已提交
215
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
216
    })
A
Annie_wang 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  }

  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 已提交
234

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

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

A
Annie_wang 已提交
239 240
| Name     | Type                   | Mandatory  | Description                     |
| -------- | --------------------- | ---- | ----------------------- |
A
Annie_wang 已提交
241 242 243 244 245 246 247 248 249
| 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. |
A
Annie_wang 已提交
250
| 12300002 | Invalid owner or options. |
A
Annie_wang 已提交
251 252 253 254
| 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 已提交
255

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

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

A
annie_wangli 已提交
264
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
265 266 267 268 269 270 271 272 273
    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 已提交
274
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
275
    })
A
annie_wangli 已提交
276
  }
A
annie_wangli 已提交
277

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

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

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

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

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

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

A
Annie_wang 已提交
302 303
| Name     | Type                       | Mandatory  | Description              |
| -------- | ------------------------- | ---- | ---------------- |
A
Annie_wang 已提交
304 305 306 307 308 309 310 311 312 313
| 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 已提交
314 315

**Example**
A
annie_wangli 已提交
316

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

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

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

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

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

**Parameters**
A
annie_wangli 已提交
340

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

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

A
Annie_wang 已提交
347 348
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
349 350 351 352 353 354 355 356 357
| 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 已提交
358

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

Z
zhangalong 已提交
361
  ```js
A
Annie_wang 已提交
362 363 364 365 366 367 368 369 370
  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 已提交
371 372
  ```

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

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

A
Annie_wang 已提交
377
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 已提交
378

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

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

A
Annie_wang 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
| 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 已提交
398 399

**Example**
A
annie_wangli 已提交
400

Z
zhangalong 已提交
401
  ```js
A
Annie_wang 已提交
402 403 404 405 406 407 408 409 410 411 412
  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 已提交
413 414
  ```

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

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

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

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

**Parameters**
A
annie_wangli 已提交
424

A
Annie_wang 已提交
425 426 427 428 429
| 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 已提交
430

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

A
Annie_wang 已提交
433 434
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
435 436 437 438 439 440 441 442 443 444
| 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 已提交
445

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

Z
zhangalong 已提交
448
  ```js
A
Annie_wang 已提交
449 450 451 452 453 454 455 456 457
  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 已提交
458 459
  ```

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

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

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

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

**Parameters**
A
annie_wangli 已提交
469

A
Annie_wang 已提交
470 471 472
| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                          |
A
Annie_wang 已提交
473
| bundleName | string                    | Yes   | Bundle name of the app.                        |
A
Annie_wang 已提交
474 475 476 477 478 479 480 481 482
| 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. |
A
annie_wangli 已提交
483

A
annie_wangli 已提交
484
**Example**
A
annie_wangli 已提交
485

Z
zhangalong 已提交
486
  ```js
A
Annie_wang 已提交
487 488 489 490 491 492 493 494 495 496 497
  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 已提交
498 499
  ```

A
Annie_wang 已提交
500
### checkAppAccess<sup>9+</sup>
A
annie_wangli 已提交
501

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

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

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

A
annie_wangli 已提交
508
**Parameters**
A
annie_wangli 已提交
509

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

A
Annie_wang 已提交
515
**Return value**
A
annie_wangli 已提交
516

A
Annie_wang 已提交
517 518 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
| 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. |

**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 已提交
600 601
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
602 603 604 605 606 607 608 609 610
| 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 已提交
611 612

**Example**
A
annie_wangli 已提交
613

Z
zhangalong 已提交
614
  ```js
A
Annie_wang 已提交
615 616 617 618 619 620 621 622 623
  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 已提交
624 625
  ```

A
Annie_wang 已提交
626
### checkDataSyncEnabled<sup>9+</sup>
A
annie_wangli 已提交
627

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

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

A
Annie_wang 已提交
632
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
633 634

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

A
annie_wangli 已提交
636
**Parameters**
A
annie_wangli 已提交
637

A
Annie_wang 已提交
638 639 640
| Name     | Type                          | Mandatory  | Description                   |
| -------- | ---------------------------- | ---- | --------------------- |
| name     | string                       | Yes   | Name of the target app account.              |
A
Annie_wang 已提交
641 642 643 644 645 646 647 648 649
| 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 已提交
650

A
annie_wangli 已提交
651
**Example**
A
annie_wangli 已提交
652

Z
zhangalong 已提交
653
  ```js
A
Annie_wang 已提交
654 655 656 657 658 659 660 661 662 663 664
  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 已提交
665 666
  ```

A
Annie_wang 已提交
667
### checkDataSyncEnabled<sup>9+</sup>
A
annie_wangli 已提交
668

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

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

A
Annie_wang 已提交
673
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
674

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

A
annie_wangli 已提交
677
**Parameters**
A
annie_wangli 已提交
678

A
Annie_wang 已提交
679 680 681
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|
A
annie_wangli 已提交
682

A
Annie_wang 已提交
683
**Return value**
A
annie_wangli 已提交
684

A
Annie_wang 已提交
685 686
| Type                    | Description                   |
| :--------------------- | :-------------------- |
A
Annie_wang 已提交
687 688 689 690 691 692 693 694 695
| 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 已提交
696 697

**Example**
A
annie_wangli 已提交
698

Z
zhangalong 已提交
699
  ```js
A
Annie_wang 已提交
700 701 702 703 704 705 706 707 708
  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 已提交
709 710
  ```

A
Annie_wang 已提交
711
### setCredential<sup>9+</sup>
A
annie_wangli 已提交
712

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

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

A
annie_wangli 已提交
717 718 719
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
720

A
Annie_wang 已提交
721 722 723 724
| 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 已提交
725 726 727 728 729 730 731 732 733 734
| 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 已提交
735

A
annie_wangli 已提交
736
**Example**
A
annie_wangli 已提交
737

Z
zhangalong 已提交
738
  ```js
A
Annie_wang 已提交
739 740 741 742 743 744 745 746 747 748 749
  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 已提交
750 751
  ```

A
Annie_wang 已提交
752
### setCredential<sup>9+</sup>
A
annie_wangli 已提交
753

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

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

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

A
annie_wangli 已提交
760
**Parameters**
A
annie_wangli 已提交
761

A
Annie_wang 已提交
762 763 764 765
| 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 已提交
766
| credential     | string | Yes   | Credential value.   |
A
annie_wangli 已提交
767

A
Annie_wang 已提交
768
**Return value**
A
annie_wangli 已提交
769

A
Annie_wang 已提交
770
| Type                | Description                   |
A
Annie_wang 已提交
771
| :------------------ | :-------------------- |
A
Annie_wang 已提交
772 773 774 775 776 777 778 779 780
| 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 已提交
781 782

**Example**
A
annie_wangli 已提交
783

Z
zhangalong 已提交
784
  ```js
A
Annie_wang 已提交
785 786 787 788 789 790 791 792 793
  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 已提交
794 795
  ```

A
Annie_wang 已提交
796
### getCredential<sup>9+</sup>
A
annie_wangli 已提交
797

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

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

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

**Parameters**
A
annie_wangli 已提交
805

A
Annie_wang 已提交
806 807 808 809 810 811 812 813 814 815 816 817 818 819
| 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 已提交
820

A
annie_wangli 已提交
821
**Example**
A
annie_wangli 已提交
822

Z
zhangalong 已提交
823
  ```js
A
Annie_wang 已提交
824 825 826 827 828 829 830 831 832 833 834
  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 已提交
835 836
  ```

A
Annie_wang 已提交
837
### getCredential<sup>9+</sup>
A
annie_wangli 已提交
838

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

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

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

A
annie_wangli 已提交
845
**Parameters**
A
annie_wangli 已提交
846

A
Annie_wang 已提交
847 848 849 850
| 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 已提交
851

A
Annie_wang 已提交
852
**Return value**
A
annie_wangli 已提交
853

A
Annie_wang 已提交
854 855 856 857 858 859 860 861 862 863 864 865
| 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 已提交
866 867

**Example**
A
annie_wangli 已提交
868

Z
zhangalong 已提交
869
  ```js
A
Annie_wang 已提交
870 871 872 873 874 875 876 877 878
  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 已提交
879 880
  ```

A
Annie_wang 已提交
881
### setCustomData<sup>9+</sup>
A
annie_wangli 已提交
882

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

A
Annie_wang 已提交
885
Sets custom data for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
886 887

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

A
annie_wangli 已提交
889
**Parameters**
A
annie_wangli 已提交
890

A
Annie_wang 已提交
891 892 893 894 895 896 897 898 899 900 901 902
| 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. |
A
Annie_wang 已提交
903
| 12300002 | Invalid name, key, or value. |
A
Annie_wang 已提交
904 905
| 12300003 | Account not found. |
| 12400003 | The number of custom data reaches the upper limit. |
A
annie_wangli 已提交
906

A
annie_wangli 已提交
907
**Example**
A
annie_wangli 已提交
908

Z
zhangalong 已提交
909
  ```js
A
Annie_wang 已提交
910 911 912 913 914 915 916 917 918 919 920
  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 已提交
921 922
  ```

A
Annie_wang 已提交
923
### setCustomData<sup>9+</sup>
A
annie_wangli 已提交
924

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

A
Annie_wang 已提交
927
Sets custom data for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
928 929

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

A
annie_wangli 已提交
931
**Parameters**
A
annie_wangli 已提交
932

A
Annie_wang 已提交
933 934 935 936 937
| 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 已提交
938

A
Annie_wang 已提交
939
**Return value**
A
annie_wangli 已提交
940

A
Annie_wang 已提交
941 942
| Type                 | Description                   |
| :------------------ | :-------------------- |
A
Annie_wang 已提交
943 944 945 946 947 948 949
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

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

A
annie_wangli 已提交
954
**Example**
A
annie_wangli 已提交
955

Z
zhangalong 已提交
956
  ```js
A
Annie_wang 已提交
957 958 959 960 961 962 963 964 965
  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 已提交
966 967
  ```

A
Annie_wang 已提交
968
### getCustomData<sup>9+</sup>
A
annie_wangli 已提交
969

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

A
Annie_wang 已提交
972
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 已提交
973

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

A
annie_wangli 已提交
976
**Parameters**
A
annie_wangli 已提交
977

A
Annie_wang 已提交
978 979 980 981 982 983 984 985 986 987 988 989 990 991
| 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 已提交
992 993

**Example**
A
annie_wangli 已提交
994

Z
zhangalong 已提交
995
  ```js
A
Annie_wang 已提交
996 997 998 999 1000 1001 1002 1003 1004 1005 1006
  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 已提交
1007 1008
  ```

A
Annie_wang 已提交
1009
### getCustomData<sup>9+</sup>
A
annie_wangli 已提交
1010

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

A
Annie_wang 已提交
1013
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 已提交
1014

A
annie_wangli 已提交
1015 1016 1017
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1018

A
Annie_wang 已提交
1019 1020 1021 1022
| 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 已提交
1023

A
Annie_wang 已提交
1024
**Return value**
A
annie_wangli 已提交
1025

A
Annie_wang 已提交
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
| 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 已提交
1038

A
annie_wangli 已提交
1039
**Example**
A
annie_wangli 已提交
1040

Z
zhangalong 已提交
1041
  ```js
A
Annie_wang 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050
  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 已提交
1051 1052
  ```

A
Annie_wang 已提交
1053
### getCustomDataSync<sup>9+</sup>
A
annie_wangli 已提交
1054

A
Annie_wang 已提交
1055
getCustomDataSync(name: string, key: string): string;
A
annie_wangli 已提交
1056

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

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

A
annie_wangli 已提交
1061
**Parameters**
A
annie_wangli 已提交
1062

A
Annie_wang 已提交
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
| 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 已提交
1082 1083

**Example**
A
annie_wangli 已提交
1084

Z
zhangalong 已提交
1085
  ```js
A
Annie_wang 已提交
1086 1087 1088 1089 1090 1091
  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 已提交
1092 1093
  ```

A
Annie_wang 已提交
1094
### getAllAccounts<sup>9+</sup>
A
annie_wangli 已提交
1095

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

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

A
annie_wangli 已提交
1100 1101 1102
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1103

A
Annie_wang 已提交
1104 1105 1106
| 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 已提交
1107

A
Annie_wang 已提交
1108
**Error codes**
A
annie_wangli 已提交
1109

A
Annie_wang 已提交
1110 1111 1112
| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
A
annie_wangli 已提交
1113

A
annie_wangli 已提交
1114
**Example**
A
annie_wangli 已提交
1115

Z
zhangalong 已提交
1116
  ```js
A
Annie_wang 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
  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 已提交
1128 1129
  ```

A
Annie_wang 已提交
1130
### getAllAccounts<sup>9+</sup>
A
annie_wangli 已提交
1131

A
Annie_wang 已提交
1132 1133 1134
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 已提交
1135

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

A
Annie_wang 已提交
1138
**Return value**
A
annie_wangli 已提交
1139

A
Annie_wang 已提交
1140 1141 1142 1143 1144 1145 1146 1147 1148
| 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 已提交
1149 1150

**Example**
A
annie_wangli 已提交
1151

Z
zhangalong 已提交
1152
  ```js
A
Annie_wang 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161
  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 已提交
1162 1163
  ```

A
Annie_wang 已提交
1164
### getAccountsByOwner<sup>9+</sup>
A
annie_wangli 已提交
1165

A
Annie_wang 已提交
1166 1167 1168
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 已提交
1169

A
annie_wangli 已提交
1170 1171 1172
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1173

A
Annie_wang 已提交
1174 1175 1176 1177
| 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 已提交
1178

A
Annie_wang 已提交
1179
**Error codes**
A
annie_wangli 已提交
1180

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

A
annie_wangli 已提交
1187
**Example**
A
annie_wangli 已提交
1188

Z
zhangalong 已提交
1189
  ```js
A
Annie_wang 已提交
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
  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 已提交
1201 1202
  ```

A
Annie_wang 已提交
1203
### getAccountsByOwner<sup>9+</sup>
A
annie_wangli 已提交
1204

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

A
Annie_wang 已提交
1207 1208
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 已提交
1209
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1210

A
annie_wangli 已提交
1211
**Parameters**
A
annie_wangli 已提交
1212

A
Annie_wang 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
| 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 已提交
1230 1231

**Example**
A
annie_wangli 已提交
1232

Z
zhangalong 已提交
1233
  ```js
A
Annie_wang 已提交
1234 1235 1236 1237 1238 1239 1240 1241 1242
  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 已提交
1243 1244
  ```

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

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

A
Annie_wang 已提交
1249
Subscribes to account information changes of apps.
A
annie_wangli 已提交
1250

A
annie_wangli 已提交
1251 1252 1253
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1254

A
Annie_wang 已提交
1255 1256 1257 1258 1259
| 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 已提交
1260

A
Annie_wang 已提交
1261
**Error codes**
A
annie_wangli 已提交
1262

A
Annie_wang 已提交
1263 1264 1265 1266 1267
| ID| Error Message|
| ------- | ------- |
| 12300001 | System service exception. |
| 12300002 | Invalid type or owners. |
| 12400001 | Application not found. |
A
annie_wangli 已提交
1268

A
annie_wangli 已提交
1269
**Example**
A
annie_wangli 已提交
1270

Z
zhangalong 已提交
1271
  ```js
A
Annie_wang 已提交
1272 1273 1274 1275 1276 1277 1278 1279
  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 已提交
1280 1281
  ```

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

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

A
Annie_wang 已提交
1286
Unsubscribes from account information changes.
A
Annie_wang 已提交
1287 1288 1289 1290 1291

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

**Parameters**

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

A
Annie_wang 已提交
1297
**Error codes**
A
Annie_wang 已提交
1298

A
Annie_wang 已提交
1299 1300 1301 1302
| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
| 12300002 | Invalid type. |
A
Annie_wang 已提交
1303 1304 1305 1306

**Example**

  ```js
A
Annie_wang 已提交
1307
  function changeOnCallback(data) {
A
Annie_wang 已提交
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
  	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 已提交
1321 1322
  ```

A
Annie_wang 已提交
1323
### auth<sup>9+</sup>
A
annie_wangli 已提交
1324

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

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

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

A
annie_wangli 已提交
1331
**Parameters**
A
annie_wangli 已提交
1332

A
Annie_wang 已提交
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
| 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. |
A
Annie_wang 已提交
1345
| 12300002 | Invalid name, owner, or authType. |
A
Annie_wang 已提交
1346 1347 1348 1349
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
A
annie_wangli 已提交
1350 1351

**Example**
A
annie_wangli 已提交
1352

Z
zhangalong 已提交
1353
  ```js
A
Annie_wang 已提交
1354

A
annie_wangli 已提交
1355

A
Annie_wang 已提交
1356 1357 1358 1359
  function onResultCallback(code, authResult) {
    console.log("resultCode: "  + code);
    console.log("authResult: "  + JSON.stringify(authResult));
  }
A
annie_wangli 已提交
1360

A
Annie_wang 已提交
1361
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
    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 已提交
1373
  }
A
annie_wangli 已提交
1374

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

A
Annie_wang 已提交
1385
### auth<sup>9+</sup>
A
annie_wangli 已提交
1386

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

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

A
annie_wangli 已提交
1391 1392 1393
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1394

A
Annie_wang 已提交
1395 1396
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
1397
| name     | string                | Yes   | Name of the target app account.    |
A
Annie_wang 已提交
1398 1399
| 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 已提交
1400 1401 1402 1403 1404 1405 1406 1407
| 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. |
A
Annie_wang 已提交
1408 1409
| 12300002 | Invalid name, owner, authType, or options. |
| 12300003 | Account not found. |
A
Annie_wang 已提交
1410 1411 1412
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
A
annie_wangli 已提交
1413

A
annie_wangli 已提交
1414
**Example**
A
annie_wangli 已提交
1415

Z
zhangalong 已提交
1416
  ```js
A
Annie_wang 已提交
1417

A
annie_wangli 已提交
1418

A
Annie_wang 已提交
1419 1420 1421
  function onResultCallback(code, authResult) {
    console.log("resultCode: "  + code);
    console.log("authResult: "  + JSON.stringify(authResult));
A
annie_wangli 已提交
1422
  }
A
annie_wangli 已提交
1423

A
annie_wangli 已提交
1424
  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
    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 已提交
1436
  }
A
annie_wangli 已提交
1437

A
Annie_wang 已提交
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
  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 已提交
1449 1450
  ```

A
Annie_wang 已提交
1451
### getAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1452

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

A
Annie_wang 已提交
1455
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 已提交
1456

A
annie_wangli 已提交
1457 1458 1459
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1460

A
Annie_wang 已提交
1461 1462 1463 1464 1465
| 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 已提交
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
| 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 已提交
1476

A
annie_wangli 已提交
1477
**Example**
A
annie_wangli 已提交
1478

Z
zhangalong 已提交
1479
  ```js
A
Annie_wang 已提交
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
  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 已提交
1491 1492
  ```

A
Annie_wang 已提交
1493
### getAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1494

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

A
Annie_wang 已提交
1497
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 已提交
1498

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

A
annie_wangli 已提交
1501
**Parameters**
A
annie_wangli 已提交
1502

A
Annie_wang 已提交
1503 1504 1505 1506 1507
| 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 已提交
1508

A
Annie_wang 已提交
1509
**Return value**
A
annie_wangli 已提交
1510

A
Annie_wang 已提交
1511
| Type                   | Description                |
A
Annie_wang 已提交
1512
| --------------------- | --------------------- |
A
Annie_wang 已提交
1513 1514 1515 1516 1517 1518 1519
| Promise&lt;string&gt; | Promise used to return the authorization token obtained.|

**Error codes**

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

**Example**
A
annie_wangli 已提交
1525

Z
zhangalong 已提交
1526
  ```js
A
Annie_wang 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535
  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 已提交
1536 1537
  ```

A
Annie_wang 已提交
1538
### setAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1539

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

A
Annie_wang 已提交
1542
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 已提交
1543

A
annie_wangli 已提交
1544 1545 1546
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1547

A
Annie_wang 已提交
1548 1549 1550 1551
| Name     | Type                       | Mandatory  | Description      |
| -------- | ------------------------- | ---- | -------- |
| name     | string                    | Yes   | Name of the target app account.|
| authType | string                    | Yes   | Authentication type.   |
A
Annie_wang 已提交
1552 1553 1554 1555 1556 1557 1558 1559
| 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. |
A
Annie_wang 已提交
1560
| 12300002 | Invalid name, authType, or token. |
A
Annie_wang 已提交
1561 1562
| 12300003 | Account not found. |
| 12400004 | The number of token reaches the upper limit. |
A
annie_wangli 已提交
1563

A
annie_wangli 已提交
1564
**Example**
A
annie_wangli 已提交
1565

Z
zhangalong 已提交
1566
  ```js
A
Annie_wang 已提交
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
  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 已提交
1578 1579
  ```

A
Annie_wang 已提交
1580
### setAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1581

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

A
Annie_wang 已提交
1584
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 已提交
1585

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

A
annie_wangli 已提交
1588
**Parameters**
A
annie_wangli 已提交
1589

A
Annie_wang 已提交
1590 1591 1592 1593
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| name     | string | Yes   | Name of the target app account.|
| authType | string | Yes   | Authentication type.   |
A
Annie_wang 已提交
1594
| token    | string | Yes   | Token to set.|
A
annie_wangli 已提交
1595

A
Annie_wang 已提交
1596
**Return value**
A
annie_wangli 已提交
1597

A
Annie_wang 已提交
1598 1599
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1600 1601 1602 1603 1604 1605 1606
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

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

**Example**
A
annie_wangli 已提交
1612

Z
zhangalong 已提交
1613
  ```js
A
Annie_wang 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622
  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 已提交
1623 1624
  ```

A
Annie_wang 已提交
1625
### deleteAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1626

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

A
Annie_wang 已提交
1629
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 已提交
1630

A
annie_wangli 已提交
1631 1632 1633
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1634

A
Annie_wang 已提交
1635 1636 1637 1638 1639
| 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 已提交
1640 1641 1642 1643 1644 1645 1646 1647
| 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. |
A
Annie_wang 已提交
1648
| 12300002 | Invalid name, owner, authType, or token. |
A
Annie_wang 已提交
1649 1650
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1651

A
annie_wangli 已提交
1652
**Example**
A
annie_wangli 已提交
1653

Z
zhangalong 已提交
1654
  ```js
A
Annie_wang 已提交
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
  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 已提交
1666 1667
  ```

A
Annie_wang 已提交
1668
### deleteAuthToken<sup>9+</sup>
A
annie_wangli 已提交
1669

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

A
Annie_wang 已提交
1672
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 已提交
1673

A
annie_wangli 已提交
1674 1675 1676
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1677

A
Annie_wang 已提交
1678 1679 1680 1681 1682
| 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 已提交
1683
| token    | string | Yes   | Authorization token to delete.|
A
annie_wangli 已提交
1684

A
Annie_wang 已提交
1685
**Return value**
A
annie_wangli 已提交
1686

A
Annie_wang 已提交
1687 1688
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1689 1690 1691 1692 1693 1694 1695
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

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

A
annie_wangli 已提交
1700
**Example**
A
annie_wangli 已提交
1701

Z
zhangalong 已提交
1702
  ```js
A
Annie_wang 已提交
1703 1704 1705 1706 1707 1708 1709 1710 1711
  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 已提交
1712 1713
  ```

A
Annie_wang 已提交
1714
### setAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1715

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

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

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

A
annie_wangli 已提交
1722
**Parameters**
A
annie_wangli 已提交
1723

A
Annie_wang 已提交
1724 1725 1726 1727 1728
| 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 已提交
1729 1730 1731 1732 1733 1734 1735 1736
| 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. |
A
Annie_wang 已提交
1737
| 12300002 | Invalid name, authType, or bundleName. |
A
Annie_wang 已提交
1738 1739 1740 1741
| 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 已提交
1742 1743

**Example**
A
annie_wangli 已提交
1744

Z
zhangalong 已提交
1745
  ```js
A
Annie_wang 已提交
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
  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 已提交
1757 1758
  ```

A
Annie_wang 已提交
1759
### setAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1760

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

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

A
annie_wangli 已提交
1765 1766 1767
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1768

A
Annie_wang 已提交
1769 1770 1771 1772 1773 1774
| 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 已提交
1775

A
Annie_wang 已提交
1776
**Return value**
A
annie_wangli 已提交
1777

A
Annie_wang 已提交
1778 1779
| Type                 | Description                   |
| ------------------- | --------------------- |
A
Annie_wang 已提交
1780 1781 1782 1783 1784 1785 1786
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| ID| Error Message|
| ------- | -------|
| 12300001 | System service exception. |
A
Annie_wang 已提交
1787
| 12300002 | Invalid name, authType, or bundleName. |
A
Annie_wang 已提交
1788 1789 1790 1791
| 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 已提交
1792

A
annie_wangli 已提交
1793
**Example**
A
annie_wangli 已提交
1794

Z
zhangalong 已提交
1795
  ```js
A
Annie_wang 已提交
1796 1797 1798 1799 1800 1801 1802 1803 1804
  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 已提交
1805 1806
  ```

A
Annie_wang 已提交
1807
### checkAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1808

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

A
Annie_wang 已提交
1811
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 已提交
1812

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

A
annie_wangli 已提交
1815
**Parameters**
A
annie_wangli 已提交
1816

A
Annie_wang 已提交
1817 1818 1819 1820 1821
| 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 已提交
1822 1823 1824 1825 1826 1827 1828
| 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. |
A
Annie_wang 已提交
1829
| 12300002 | Invalid name, authType, or bundleName. |
A
Annie_wang 已提交
1830 1831
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1832 1833

**Example**
A
annie_wangli 已提交
1834

Z
zhangalong 已提交
1835
  ```js
A
Annie_wang 已提交
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
  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 已提交
1847 1848
  ```

A
Annie_wang 已提交
1849
### checkAuthTokenVisibility<sup>9+</sup>
A
annie_wangli 已提交
1850

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

A
Annie_wang 已提交
1853
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 已提交
1854

A
annie_wangli 已提交
1855 1856 1857
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1858

A
Annie_wang 已提交
1859 1860 1861 1862 1863
| 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 已提交
1864

A
Annie_wang 已提交
1865
**Return value**
A
annie_wangli 已提交
1866

A
Annie_wang 已提交
1867 1868
| Type                    | Description                   |
| ---------------------- | --------------------- |
A
Annie_wang 已提交
1869 1870 1871 1872 1873 1874 1875
| 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. |
A
Annie_wang 已提交
1876
| 12300002 | Invalid name, authType, or bundleName. |
A
Annie_wang 已提交
1877 1878
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
A
annie_wangli 已提交
1879

A
annie_wangli 已提交
1880
**Example**
A
annie_wangli 已提交
1881

Z
zhangalong 已提交
1882
  ```js
A
Annie_wang 已提交
1883 1884 1885 1886 1887 1888 1889 1890 1891
  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 已提交
1892 1893
  ```

A
Annie_wang 已提交
1894
### getAllAuthTokens<sup>9+</sup>
A
annie_wangli 已提交
1895

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

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

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

A
annie_wangli 已提交
1902
**Parameters**
A
annie_wangli 已提交
1903

A
Annie_wang 已提交
1904 1905 1906 1907
| 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 已提交
1908 1909 1910 1911 1912 1913 1914 1915 1916
| 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 已提交
1917 1918

**Example**
A
annie_wangli 已提交
1919

Z
zhangalong 已提交
1920
  ```js
A
Annie_wang 已提交
1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931
  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 已提交
1932 1933
  ```

A
Annie_wang 已提交
1934
### getAllAuthTokens<sup>9+</sup>
A
annie_wangli 已提交
1935

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

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

A
annie_wangli 已提交
1940 1941 1942
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1943

A
Annie_wang 已提交
1944 1945 1946 1947
| 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 已提交
1948

A
Annie_wang 已提交
1949
**Return value**
A
annie_wangli 已提交
1950

A
Annie_wang 已提交
1951 1952
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
1953 1954 1955 1956 1957 1958 1959 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
| 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
A
Annie_wang 已提交
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
  import UIAbility from '@ohos.app.ability.UIAbility';

  export default class EntryAbility extends UIAbility {
    onCreate(want, param) {
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
      try {
        appAccountManager.getAuthCallback(sessionId, (err, callback) => {
          if (err != null) {
              console.log("getAuthCallback err: "  + JSON.stringify(err));
              return;
A
Annie_wang 已提交
2098
          }
A
Annie_wang 已提交
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
          var result = {
            accountInfo: {
              name: "Lisi",
              owner: "com.example.accountjsdemo",
            },
            tokenInfo: {
              token: "xxxxxx",
              authType: "getSocialData"
            }
          }; 
          callback.onResult(0, result);
        });
      } catch (err) {
          console.log("getAuthCallback exception: "  + JSON.stringify(err));
      }
A
Annie_wang 已提交
2114
    }
A
Annie_wang 已提交
2115
  }
A
Annie_wang 已提交
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
  ```

### 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
A
Annie_wang 已提交
2149
  import UIAbility from '@ohos.app.ability.UIAbility';
A
Annie_wang 已提交
2150

A
Annie_wang 已提交
2151 2152
  export default class EntryAbility extends UIAbility {
    onCreate(want, param) {
A
Annie_wang 已提交
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165
      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"
          }
        };
A
Annie_wang 已提交
2166
        callback.onResult(0, result);
A
Annie_wang 已提交
2167
        }).catch((err) => {
A
Annie_wang 已提交
2168
          console.log("getAuthCallback err: "  + JSON.stringify(err));
A
Annie_wang 已提交
2169 2170 2171 2172
        });
      } catch (err) {
        console.log("getAuthCallback exception: "  + JSON.stringify(err));
      }
A
Annie_wang 已提交
2173 2174
    }
  }
A
Annie_wang 已提交
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
  ```

### 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. |
A
Annie_wang 已提交
2280
| 12300002 | Invalid name, owner, or labels. |
A
Annie_wang 已提交
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
| 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. |
A
Annie_wang 已提交
2330
| 12300002 | Invalid name, owner, or labels. |
A
Annie_wang 已提交
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
| 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 已提交
2375

A
annie_wangli 已提交
2376
**Example**
A
annie_wangli 已提交
2377

A
Annie_wang 已提交
2378 2379 2380 2381 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
  ```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. |
A
Annie_wang 已提交
2593
| 12300002 | Invalid name, owner, or options. |
A
Annie_wang 已提交
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
| 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 已提交
2729
| name     | string                    | Yes   | Name of the app account to add.         |
A
Annie_wang 已提交
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
| 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 已提交
2747
> 
A
Annie_wang 已提交
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773
> 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 已提交
2774 2775
> **NOTE**
> 
A
Annie_wang 已提交
2776 2777 2778 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
> 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 已提交
2827

A
Annie_wang 已提交
2828 2829 2830 2831 2832 2833 2834

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

  function onRequestRedirectedCallback(request) {
A
Annie_wang 已提交
2835 2836 2837 2838 2839 2840 2841 2842 2843
    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 已提交
2844
      console.log("startAbility err: " + JSON.stringify(err));
A
Annie_wang 已提交
2845
    })
A
Annie_wang 已提交
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869
  }

  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 已提交
2870
| name     | string                    | Yes   | Name of the app account to delete.     |
A
Annie_wang 已提交
2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896
| 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 已提交
2897
| name | string | Yes   | Name of the app account to delete.|
A
Annie_wang 已提交
2898 2899 2900 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

**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 已提交
3123
| credentialType | string                    | Yes   | Type of the credential to set.    |
A
Annie_wang 已提交
3124 3125 3126 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
| 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 已提交
3152
| credentialType | string | Yes   | Type of the credential to set.|
A
Annie_wang 已提交
3153 3154 3155 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
| 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 已提交
3514
| credentialType | string                      | Yes   | Type of the credential to obtain.|
A
Annie_wang 已提交
3515 3516 3517 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
| 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 已提交
3543
| credentialType | string | Yes   | Type of the credential to obtain.|
A
Annie_wang 已提交
3544 3545 3546 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

**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 已提交
3723
off(type: 'change', callback?: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
Annie_wang 已提交
3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737

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 已提交
3738
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | No   | Callback to unregister.|
A
Annie_wang 已提交
3739 3740 3741 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

**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 已提交
3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798
    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 已提交
3799 3800 3801 3802 3803
  }

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

A
Annie_wang 已提交
3807
### getOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3808

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

A
Annie_wang 已提交
3811 3812 3813 3814 3815
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 已提交
3816

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

A
annie_wangli 已提交
3819
**Parameters**
A
annie_wangli 已提交
3820

A
Annie_wang 已提交
3821 3822 3823 3824 3825 3826
| 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 已提交
3827 3828

**Example**
A
annie_wangli 已提交
3829

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

A
Annie_wang 已提交
3837
### getOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3838

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

A
Annie_wang 已提交
3841 3842 3843 3844 3845
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 已提交
3846

A
annie_wangli 已提交
3847 3848 3849
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3850

A
Annie_wang 已提交
3851 3852 3853 3854 3855
| 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 已提交
3856

A
Annie_wang 已提交
3857
**Return value**
A
annie_wangli 已提交
3858

A
Annie_wang 已提交
3859 3860 3861
| Type                   | Description                   |
| --------------------- | --------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
3862

A
annie_wangli 已提交
3863
**Example**
A
annie_wangli 已提交
3864

Z
zhangalong 已提交
3865
  ```js
A
Annie_wang 已提交
3866 3867
  appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => {
       console.log('getOAuthToken token: ' + data);
A
annie_wangli 已提交
3868
  }).catch((err) => {
A
Annie_wang 已提交
3869
      console.log("getOAuthToken err: "  + JSON.stringify(err));
A
annie_wangli 已提交
3870 3871 3872
  });
  ```

A
Annie_wang 已提交
3873
### setOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3874

A
Annie_wang 已提交
3875
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
3876

A
Annie_wang 已提交
3877 3878 3879 3880 3881
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 已提交
3882

A
annie_wangli 已提交
3883 3884 3885
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3886

A
Annie_wang 已提交
3887 3888 3889 3890 3891 3892
| 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 已提交
3893

A
annie_wangli 已提交
3894
**Example**
A
annie_wangli 已提交
3895

Z
zhangalong 已提交
3896
  ```js
A
Annie_wang 已提交
3897 3898
  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3899 3900 3901
  });
  ```

A
Annie_wang 已提交
3902
### setOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3903

A
Annie_wang 已提交
3904
setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
3905

A
Annie_wang 已提交
3906 3907 3908 3909 3910
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 已提交
3911

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

A
annie_wangli 已提交
3914
**Parameters**
A
annie_wangli 已提交
3915

A
Annie_wang 已提交
3916 3917 3918 3919 3920
| 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 已提交
3921

A
Annie_wang 已提交
3922
**Return value**
A
annie_wangli 已提交
3923

A
Annie_wang 已提交
3924 3925 3926
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
3927 3928

**Example**
A
annie_wangli 已提交
3929

Z
zhangalong 已提交
3930
  ```js
A
Annie_wang 已提交
3931 3932
  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
      console.log('setOAuthToken successfully');
A
annie_wangli 已提交
3933
  }).catch((err) => {
A
Annie_wang 已提交
3934
      console.log('setOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3935 3936 3937
  });
  ```

A
Annie_wang 已提交
3938
### deleteOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3939

A
Annie_wang 已提交
3940 3941 3942
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 已提交
3943

A
Annie_wang 已提交
3944 3945 3946
> **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 已提交
3947

A
annie_wangli 已提交
3948 3949 3950
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
3951

A
Annie_wang 已提交
3952 3953 3954 3955 3956 3957 3958
| 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 已提交
3959

A
annie_wangli 已提交
3960
**Example**
A
annie_wangli 已提交
3961

Z
zhangalong 已提交
3962
  ```js
A
Annie_wang 已提交
3963 3964
  appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => {
       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
A
annie_wangli 已提交
3965 3966 3967
  });
  ```

A
Annie_wang 已提交
3968
### deleteOAuthToken<sup>(deprecated)</sup>
A
annie_wangli 已提交
3969

A
Annie_wang 已提交
3970 3971 3972
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 已提交
3973

A
Annie_wang 已提交
3974 3975 3976
> **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 已提交
3977

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

A
annie_wangli 已提交
3980
**Parameters**
A
annie_wangli 已提交
3981

A
Annie_wang 已提交
3982 3983 3984 3985 3986 3987
| 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 已提交
3988

A
Annie_wang 已提交
3989
**Return value**
A
annie_wangli 已提交
3990

A
Annie_wang 已提交
3991 3992 3993
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
3994 3995

**Example**
A
annie_wangli 已提交
3996

Z
zhangalong 已提交
3997
  ```js
A
Annie_wang 已提交
3998 3999
  appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => {
       console.log('deleteOAuthToken successfully');
A
annie_wangli 已提交
4000
  }).catch((err) => {
A
Annie_wang 已提交
4001
      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
A
annie_wangli 已提交
4002 4003 4004
  });
  ```

A
Annie_wang 已提交
4005
### setOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4006

A
Annie_wang 已提交
4007 4008 4009
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 已提交
4010

A
Annie_wang 已提交
4011 4012 4013
> **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 已提交
4014 4015 4016 4017 4018

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

**Parameters**

A
Annie_wang 已提交
4019 4020 4021 4022 4023 4024 4025
| 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 已提交
4026 4027 4028 4029

**Example**

  ```js
A
Annie_wang 已提交
4030 4031
  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => {
       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4032 4033 4034
  });
  ```

A
Annie_wang 已提交
4035
### setOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4036

A
Annie_wang 已提交
4037 4038 4039
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 已提交
4040

A
Annie_wang 已提交
4041 4042 4043
> **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 已提交
4044 4045 4046 4047 4048

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

**Parameters**

A
Annie_wang 已提交
4049 4050 4051 4052 4053 4054
| 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 已提交
4055

A
Annie_wang 已提交
4056
**Return value**
A
Annie_wang 已提交
4057

A
Annie_wang 已提交
4058 4059 4060
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
A
Annie_wang 已提交
4061 4062 4063 4064

**Example**

  ```js
A
Annie_wang 已提交
4065 4066
  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => {
      console.log('setOAuthTokenVisibility successfully');
A
Annie_wang 已提交
4067
  }).catch((err) => {
A
Annie_wang 已提交
4068
      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4069 4070 4071
  });
  ```

A
Annie_wang 已提交
4072
### checkOAuthTokenVisibility<sup>(deprecated)</sup>
A
Annie_wang 已提交
4073

A
Annie_wang 已提交
4074 4075 4076
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 已提交
4077

A
Annie_wang 已提交
4078 4079 4080
> **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 已提交
4081 4082 4083 4084 4085

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

**Parameters**

A
Annie_wang 已提交
4086 4087 4088 4089 4090 4091
| 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 已提交
4092 4093 4094 4095

**Example**

  ```js
A
Annie_wang 已提交
4096 4097 4098
  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
A
Annie_wang 已提交
4099 4100 4101
  });
  ```

A
Annie_wang 已提交
4102 4103 4104
### checkOAuthTokenVisibility<sup>(deprecated)</sup>

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
A
Annie_wang 已提交
4105

A
Annie_wang 已提交
4106
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 已提交
4107

A
Annie_wang 已提交
4108 4109 4110
> **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 已提交
4111 4112 4113 4114 4115

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

**Parameters**

A
Annie_wang 已提交
4116 4117 4118 4119 4120
| 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 已提交
4121

A
Annie_wang 已提交
4122
**Return value**
A
Annie_wang 已提交
4123

A
Annie_wang 已提交
4124 4125 4126
| 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 已提交
4127 4128 4129 4130

**Example**

  ```js
A
Annie_wang 已提交
4131 4132
  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => {
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
A
Annie_wang 已提交
4133
  }).catch((err) => {
A
Annie_wang 已提交
4134
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
A
Annie_wang 已提交
4135 4136 4137
  });
  ```

A
Annie_wang 已提交
4138
### getAllOAuthTokens<sup>(deprecated)</sup>
A
Annie_wang 已提交
4139

A
Annie_wang 已提交
4140 4141 4142
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 已提交
4143

A
Annie_wang 已提交
4144 4145 4146
> **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 已提交
4147 4148 4149 4150 4151

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

**Parameters**

A
Annie_wang 已提交
4152 4153 4154 4155 4156
| 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 已提交
4157 4158 4159 4160

**Example**

  ```js
A
Annie_wang 已提交
4161 4162 4163
  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 已提交
4164 4165 4166
  });
  ```

A
Annie_wang 已提交
4167
### getAllOAuthTokens<sup>(deprecated)</sup>
A
Annie_wang 已提交
4168

A
Annie_wang 已提交
4169
getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
A
Annie_wang 已提交
4170

A
Annie_wang 已提交
4171 4172 4173 4174 4175
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 已提交
4176 4177 4178 4179 4180

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

**Parameters**

A
Annie_wang 已提交
4181 4182 4183 4184
| 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 已提交
4185

A
Annie_wang 已提交
4186
**Return value**
A
Annie_wang 已提交
4187

A
Annie_wang 已提交
4188 4189 4190
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt; [OAuthTokenInfo](#oauthtokeninfodeprecated)&gt;&gt; | Promise used to return the tokens obtained.|
A
Annie_wang 已提交
4191 4192 4193 4194

**Example**

  ```js
A
Annie_wang 已提交
4195 4196
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => {
      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4197
  }).catch((err) => {
A
Annie_wang 已提交
4198
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4199 4200 4201
  });
  ```

A
Annie_wang 已提交
4202 4203 4204
### getOAuthList<sup>(deprecated)</sup>

getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
Annie_wang 已提交
4205

A
Annie_wang 已提交
4206
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 已提交
4207

A
Annie_wang 已提交
4208 4209 4210
> **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 已提交
4211 4212 4213 4214 4215

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

**Parameters**

A
Annie_wang 已提交
4216 4217 4218 4219 4220
| 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 已提交
4221 4222 4223 4224

**Example**

  ```js
A
Annie_wang 已提交
4225 4226 4227
  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 已提交
4228 4229 4230
  });
  ```

A
Annie_wang 已提交
4231
### getOAuthList<sup>(deprecated)</sup>
A
Annie_wang 已提交
4232

A
Annie_wang 已提交
4233
getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
A
Annie_wang 已提交
4234

A
Annie_wang 已提交
4235 4236 4237 4238 4239
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 已提交
4240 4241 4242 4243 4244

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

**Parameters**

A
Annie_wang 已提交
4245 4246 4247 4248
| Name     | Type    | Mandatory  | Description                     |
| -------- | ------ | ---- | ----------------------- |
| name     | string | Yes   | Name of the target app account.               |
| authType | string | Yes   | Authentication type.|
A
Annie_wang 已提交
4249

A
Annie_wang 已提交
4250
**Return value**
A
Annie_wang 已提交
4251

A
Annie_wang 已提交
4252 4253 4254
| Type                                | Description                   |
| ---------------------------------- | --------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return a list of authorized bundles.|
A
Annie_wang 已提交
4255 4256 4257 4258

**Example**

  ```js
A
Annie_wang 已提交
4259 4260
  appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => {
       console.log('getOAuthList data: ' + JSON.stringify(data));
A
Annie_wang 已提交
4261
  }).catch((err) => {
A
Annie_wang 已提交
4262
      console.log("getOAuthList err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4263 4264 4265
  });
  ```

A
Annie_wang 已提交
4266
### getAuthenticatorCallback<sup>(deprecated)</sup>
A
Annie_wang 已提交
4267

A
Annie_wang 已提交
4268
getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
A
Annie_wang 已提交
4269

A
Annie_wang 已提交
4270 4271 4272 4273 4274
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 已提交
4275 4276 4277 4278 4279

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

**Parameters**

A
Annie_wang 已提交
4280 4281 4282 4283
| 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 已提交
4284 4285 4286 4287

**Example**

  ```js
A
Annie_wang 已提交
4288 4289 4290 4291 4292 4293
  import UIAbility from '@ohos.app.ability.UIAbility';

  export default class EntryAbility extends UIAbility {
    onCreate(want, param) {
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
      appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
A
Annie_wang 已提交
4294 4295 4296 4297 4298 4299 4300 4301 4302
        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 已提交
4303 4304 4305
      });
    }
  }
A
Annie_wang 已提交
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
  import UIAbility from '@ohos.app.ability.UIAbility';
A
Annie_wang 已提交
4336

A
Annie_wang 已提交
4337 4338
  export default class EntryAbility extends UIAbility {
    onCreate(want, param) {
A
Annie_wang 已提交
4339 4340
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
Annie_wang 已提交
4341 4342 4343 4344 4345
        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 已提交
4346
      }).catch((err) => {
A
Annie_wang 已提交
4347
        console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
A
Annie_wang 已提交
4348
      });
A
Annie_wang 已提交
4349 4350
    }
  }
A
Annie_wang 已提交
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**
> 
A
Annie_wang 已提交
4566
> 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 已提交
4567

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

A
Annie_wang 已提交
4570
| Name                                 | Value  | Description          |
A
Annie_wang 已提交
4571 4572 4573
| ----------------------------------- | ----- | ------------ |
| SUCCESS                             | 0     | The operation is successful.     |
| ERROR_ACCOUNT_NOT_EXIST             | 10001 | The app account does not exist.  |
A
Annie_wang 已提交
4574
| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. |
A
Annie_wang 已提交
4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585
| 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 已提交
4586
| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | The authorization token does not exist.|
A
Annie_wang 已提交
4587 4588 4589 4590
| 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 已提交
4591

A
Annie_wang 已提交
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 4694
## 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 已提交
4695

A
Annie_wang 已提交
4696
Provides OAuth authenticator callbacks.
A
annie_wangli 已提交
4697

A
Annie_wang 已提交
4698 4699 4700 4701
> **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 已提交
4702 4703
### onResult<sup>8+</sup>

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

A
Annie_wang 已提交
4706
Called to return the result of an authentication request.
A
annie_wangli 已提交
4707

A
annie_wangli 已提交
4708 4709 4710
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4711

A
Annie_wang 已提交
4712 4713 4714 4715
| Name   | Type                  | Mandatory  | Description    |
| ------ | -------------------- | ---- | ------ |
| code   | number               | Yes   | Authentication result code.|
| result | {[key: string]: any} | Yes   | Authentication result. |
A
annie_wangli 已提交
4716

A
annie_wangli 已提交
4717
**Example**
A
annie_wangli 已提交
4718

Z
zhangalong 已提交
4719
  ```js
A
Annie_wang 已提交
4720
  let appAccountManager = account_appAccount.createAppAccountManager();
A
annie_wangli 已提交
4721 4722
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
4723
      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
A
Annie_wang 已提交
4724
                    [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo",
A
Annie_wang 已提交
4725
                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
A
annie_wangli 已提交
4726
                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
A
Annie_wang 已提交
4727
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
4728 4729 4730 4731 4732 4733 4734
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

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

A
annie_wangli 已提交
4735
onRequestRedirected: (request: Want) =&gt; void
A
annie_wangli 已提交
4736

A
Annie_wang 已提交
4737
Called to redirect a request.
A
annie_wangli 已提交
4738

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

A
annie_wangli 已提交
4741
**Parameters**
A
Annie_wang 已提交
4742

A
Annie_wang 已提交
4743 4744 4745
| Name    | Type  | Mandatory  | Description        |
| ------- | ---- | ---- | ---------- |
| request | Want | Yes   | Request to be redirected.|
A
annie_wangli 已提交
4746 4747

**Example**
A
annie_wangli 已提交
4748

Z
zhangalong 已提交
4749
  ```js
A
annie_wangli 已提交
4750 4751 4752
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
A
Annie_wang 已提交
4753 4754
              bundleName: "com.example.accountjsdemo",
              abilityName: "com.example.accountjsdemo.LoginAbility",
A
annie_wangli 已提交
4755 4756
          });
      }
A
annie_wangli 已提交
4757

A
annie_wangli 已提交
4758
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
4759 4760 4761 4762
          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 已提交
4763 4764 4765 4766
      }
  }
  ```

A
Annie_wang 已提交
4767 4768
### onRequestContinued<sup>9+</sup>

A
Annie_wang 已提交
4769
onRequestContinued?: () =&gt; void
A
Annie_wang 已提交
4770

A
Annie_wang 已提交
4771
Called to continue to process the request.
A
Annie_wang 已提交
4772 4773 4774 4775 4776 4777

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

**Example**

  ```js
A
Annie_wang 已提交
4778
  let appAccountManager = account_appAccount.createAppAccountManager();
A
Annie_wang 已提交
4779 4780
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
Annie_wang 已提交
4781
      callback.onRequestContinued();
A
Annie_wang 已提交
4782 4783 4784 4785 4786
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
4787 4788
## Authenticator<sup>8+</sup>

A
Annie_wang 已提交
4789
Provides APIs to operate the authenticator.
A
annie_wangli 已提交
4790

A
Annie_wang 已提交
4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802
### 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 已提交
4803
| options          | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9)  | Yes   | Options for implicitly creating an account.     |
A
Annie_wang 已提交
4804 4805
| callback         | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|

A
Annie_wang 已提交
4806
### addAccountImplicitly<sup>(deprecated)</sup>
A
annie_wangli 已提交
4807

A
annie_wangli 已提交
4808
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
4809

A
Annie_wang 已提交
4810 4811 4812 4813 4814
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 已提交
4815

A
annie_wangli 已提交
4816 4817 4818
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4819

A
Annie_wang 已提交
4820 4821 4822 4823 4824
| 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 已提交
4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843
| 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 已提交
4844

A
Annie_wang 已提交
4845
### authenticate<sup>(deprecated)</sup>
A
annie_wangli 已提交
4846

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

A
Annie_wang 已提交
4849 4850 4851 4852 4853
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 已提交
4854

A
annie_wangli 已提交
4855 4856 4857
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
4858

A
Annie_wang 已提交
4859 4860 4861 4862 4863 4864
| 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 已提交
4865
| callback         | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes   | Authenticator callback invoked to return the authentication result.|
A
Annie_wang 已提交
4866 4867 4868

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

A
Annie_wang 已提交
4869
verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void;
A
Annie_wang 已提交
4870

A
Annie_wang 已提交
4871
Verifies the credential of an app account. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4872 4873 4874 4875

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

**Parameters**
A
Annie_wang 已提交
4876

A
Annie_wang 已提交
4877 4878
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4879
| name      | string                   | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4880
| options   | [VerifyCredentialOptions](#verifycredentialoptions9)  | Yes   | Options for credential verification.           |
A
Annie_wang 已提交
4881
| callback  | [AuthCallback](#authcallback9)    | Yes   | Authenticator callback invoked to return the verification result.|
A
Annie_wang 已提交
4882 4883 4884

### setProperties<sup>9+</sup>

A
Annie_wang 已提交
4885
setProperties(options: SetPropertiesOptions, callback: AuthCallback): void;
A
Annie_wang 已提交
4886

A
Annie_wang 已提交
4887
Sets the authenticator properties. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
4888 4889 4890 4891

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

**Parameters**
A
Annie_wang 已提交
4892

A
Annie_wang 已提交
4893 4894 4895
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| options   | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.           |
A
Annie_wang 已提交
4896
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
4897 4898 4899

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

A
Annie_wang 已提交
4900
checkAccountLabels(name: string, labels: Array&lt;string&gt;, callback: AuthCallback): void;
A
Annie_wang 已提交
4901 4902 4903 4904 4905 4906

Checks the account labels. This API uses an asynchronous callback to return the result.

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

**Parameters**
A
Annie_wang 已提交
4907

A
Annie_wang 已提交
4908 4909
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4910
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4911
| labels    | Array&lt;string&gt;          | Yes   | Labels to check.                  |
A
Annie_wang 已提交
4912
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the check result.|
A
Annie_wang 已提交
4913

A
Annie_wang 已提交
4914
### checkAccountRemovable<sup>9+</sup>
A
Annie_wang 已提交
4915

A
Annie_wang 已提交
4916
checkAccountRemovable(name: string, callback: AuthCallback): void;
A
Annie_wang 已提交
4917 4918 4919 4920 4921 4922

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 已提交
4923

A
Annie_wang 已提交
4924 4925
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
4926
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
4927
| callback  | [AuthCallback](#authcallback9) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
4928 4929 4930 4931 4932 4933 4934 4935

### 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 已提交
4936

A
annie_wangli 已提交
4937
**Example**
A
annie_wangli 已提交
4938

Z
zhangalong 已提交
4939
  ```js
A
annie_wangli 已提交
4940
  class MyAuthenticator extends account_appAccount.Authenticator {
A
Annie_wang 已提交
4941 4942 4943 4944 4945 4946
    addAccountImplicitly(authType, callerBundleName, options, callback) {
      callback.onRequestRedirected({
        bundleName: "com.example.accountjsdemo",
        abilityName: "com.example.accountjsdemo.LoginAbility",
      });
    }
A
annie_wangli 已提交
4947

A
Annie_wang 已提交
4948 4949 4950 4951 4952 4953
    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 已提交
4954

A
Annie_wang 已提交
4955 4956 4957 4958 4959 4960 4961 4962 4963
    verifyCredential(name, options, callback) {
      callback.onRequestRedirected({
        bundleName: "com.example.accountjsdemo",
        abilityName: "com.example.accountjsdemo.VerifyAbility",
        parameters: {
          name: name
        }
      });
    }
A
Annie_wang 已提交
4964

A
Annie_wang 已提交
4965 4966 4967
    setProperties(options, callback) {
      callback.onResult(account_appAccount.ResultCode.SUCCESS, {});
    }
A
Annie_wang 已提交
4968

A
Annie_wang 已提交
4969 4970 4971 4972 4973
    checkAccountLabels(name, labels, callback) {
      var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false};
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
  
A
Annie_wang 已提交
4974
    checkAccountRemovable(name, callback) {
A
Annie_wang 已提交
4975 4976 4977
      var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true};
      callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
A
annie_wangli 已提交
4978
  }
A
Annie_wang 已提交
4979
  var authenticator = null;
A
annie_wangli 已提交
4980
  export default {
A
Annie_wang 已提交
4981 4982 4983 4984
    onConnect(want) {
      authenticator = new MyAuthenticator();
      return authenticator.getRemoteObject();
    }
A
annie_wangli 已提交
4985
  }
A
Annie_wang 已提交
4986
  ```