openharmony 鸿蒙 js-apis-oaid

2025-06-12 浏览 (1)

@ohos.identifier.oaid (OAID)

The OAID module provides APIs for obtaining Open Anonymous Device Identifiers (OAIDs).

NOTE

Modules to Import

import { identifier } from '@kit.AdsKit';

identifier.getOAID

getOAID(): Promise<string>

Obtains an OAID. This API uses a promise to return the result.

Required permissions: ohos.permission.APP_TRACKING_CONSENT

System capability: SystemCapability.Advertising.OAID

Return value

TypeDescription
Promise<string>Promise used to return the OAID.
1. If the application has configured the permission ohos.permission.APP_TRACKING_CONSENT and the permission is allowed, the OAID is returned.
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.
3. If the application has not configured the permission ohos.permission.APP_TRACKING_CONSENT, 00000000-0000-0000-0000-000000000000 is returned.

Error codes

For details about the following error codes, see OAID Error Codes.

IDError Message
17300001System internal error.

Example

import { identifier } from '@kit.AdsKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

identifier.getOAID().then((data) => {
  const oaid: string = data;
  hilog.info(0x0000, 'testTag', `Succeed in getting oaid. Oaid is ${oaid}`);
}).catch((err: BusinessError) => {
  hilog.error(0x0000, 'testTag', `Fail to get oaid. Code is ${err.code}, message is ${err.message}`);
})

identifier.getOAID

getOAID(callback: AsyncCallback<string>): void

Obtains an OAID. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.APP_TRACKING_CONSENT

System capability: SystemCapability.Advertising.OAID

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesCallback used to return the OAID.
1. If the application has configured the permission ohos.permission.APP_TRACKING_CONSENT and the permission is allowed, the OAID is returned.
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.
3. If the application has not configured the permission ohos.permission.APP_TRACKING_CONSENT, 00000000-0000-0000-0000-000000000000 is returned.

Error codes

For details about the following error codes, see OAID Error Codes.

IDError Message
17300001System internal error.

Example

import { identifier } from '@kit.AdsKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
 
identifier.getOAID((err: BusinessError, data: string) => {
  if (err.code) {
    hilog.error(0x0000, 'testTag', `Fail to get oaid. Code is ${err.code}, message is ${err.message}`);
  } else {
    const oaid: string = data;
    hilog.info(0x0000, 'testTag', `Succeed in getting oaid. Oaid is ${oaid}`);
  }
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ads Kit

harmony 鸿蒙Ads Service Framework Error Codes

harmony 鸿蒙OAID Error Codes

harmony 鸿蒙@ohos.advertising.AdComponent (Non-Full-Screen Ad Component)

harmony 鸿蒙@ohos.advertising.AdsServiceExtensionAbility (ExtensionAbility for Ads) (System API)

harmony 鸿蒙@ohos.advertising.AdsServiceExtensionAbility (ExtensionAbility for Ads)

harmony 鸿蒙@ohos.advertising (Ads Service Framework)

harmony 鸿蒙@ohos.advertising.AutoAdComponent (Carousel Ad Component)

harmony 鸿蒙Advertisement

harmony 鸿蒙@ohos.identifier.oaid (OAID) (System API)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/H09W9z