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