1e41f4b71Sopenharmony_ci# @ohos.identifier.oaid (OAID)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **OAID** module provides APIs for obtaining Open Anonymous Device Identifiers (OAIDs).
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **NOTE**
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> To use the APIs for obtaining OAIDs, you must [request the ohos.permission.APP_TRACKING_CONSENT permission](../../security/AccessToken/request-user-authorization.md).
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## Modules to Import
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci```
17e41f4b71Sopenharmony_ciimport { identifier } from '@kit.AdsKit';
18e41f4b71Sopenharmony_ci```
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## identifier.getOAID
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cigetOAID(): Promise<string>
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciObtains an OAID. This API uses a promise to return the result.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Advertising.OAID
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Return value**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Type| Description| 
34e41f4b71Sopenharmony_ci| -------- | -------- |
35e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise used to return the OAID.<br>1. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is allowed, the OAID is returned.<br>2. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned.<br>3. If the application has not configured the permission **ohos.permission.APP_TRACKING_CONSENT**, 00000000-0000-0000-0000-000000000000 is returned.| 
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Error codes**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciFor details about the following error codes, see [OAID Error Codes](errorcode-oaid.md).
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| ID| Error Message| 
42e41f4b71Sopenharmony_ci| -------- | -------- |
43e41f4b71Sopenharmony_ci| 17300001 | System&nbsp;internal&nbsp;error. | 
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Example**
46e41f4b71Sopenharmony_ci```
47e41f4b71Sopenharmony_ciimport { identifier } from '@kit.AdsKit';
48e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
49e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_citry {
52e41f4b71Sopenharmony_ci  identifier.getOAID().then((data) => {
53e41f4b71Sopenharmony_ci    const oaid: string = data;
54e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', `succeeded in getting oaid by promise, oaid: ${oaid}`);
55e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
56e41f4b71Sopenharmony_ci    hilog.error(0x0000, 'testTag', '%{public}s',
57e41f4b71Sopenharmony_ci      `get oaid by promise failed, code: ${err.code}, message: ${err.message}`);
58e41f4b71Sopenharmony_ci  })
59e41f4b71Sopenharmony_ci} catch (err) {
60e41f4b71Sopenharmony_ci  hilog.error(0x0000, 'testTag', '%{public}s', `get oaid by promise catch error: ${err.code} ${err.message}`);
61e41f4b71Sopenharmony_ci}
62e41f4b71Sopenharmony_ci```
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci## identifier.getOAID
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_cigetOAID(callback: AsyncCallback&lt;string&gt;): void
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciObtains an OAID. This API uses an asynchronous callback to return the result.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Advertising.OAID
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Parameters**
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 
79e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
80e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the OAID.<br>1. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the is allowed, the OAID is returned.<br>2. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned.<br>3. If the application has not configured the permission **ohos.permission.APP_TRACKING_CONSENT**, 00000000-0000-0000-0000-000000000000 is returned.| 
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Error codes**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciFor details about the following error codes, see [OAID Error Codes](errorcode-oaid.md).
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci| ID| Error Message| 
90e41f4b71Sopenharmony_ci| -------- | -------- |
91e41f4b71Sopenharmony_ci| 17300001 | System&nbsp;internal&nbsp;error. | 
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Example**
95e41f4b71Sopenharmony_ci```
96e41f4b71Sopenharmony_ciimport { identifier } from '@kit.AdsKit';
97e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
98e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
99e41f4b71Sopenharmony_ci 
100e41f4b71Sopenharmony_citry {
101e41f4b71Sopenharmony_ci  identifier.getOAID((err: BusinessError, data: string) => {
102e41f4b71Sopenharmony_ci    if (err.code) {
103e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', '%{public}s', `get oaid by callback failed, error: ${err.code} ${err.message}`);
104e41f4b71Sopenharmony_ci    } else {
105e41f4b71Sopenharmony_ci      const oaid: string = data;
106e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', '%{public}s', 'succeed in getting oaid by callback');
107e41f4b71Sopenharmony_ci    }
108e41f4b71Sopenharmony_ci   });
109e41f4b71Sopenharmony_ci} catch (err) {
110e41f4b71Sopenharmony_ci  hilog.error(0x0000, 'testTag', '%{public}s', `get oaid by callback catch error: ${err.code} ${err.message}`);
111e41f4b71Sopenharmony_ci}
112e41f4b71Sopenharmony_ci```
113