Ads Kit provides traffic monetization services, through which developers can display banner, native, rewarded ads and other forms of advertising content to users in their own apps. For the online advertising space in the application, because it involves income, daily data monitoring is particularly important.

For this purpose, the advertising service also provides a traffic monetization service reporting API (Publisher Service Reporting API). By accessing this API, developers can obtain data related to in-app advertising monetization, including ad request volume, return volume, display rate, click-through rate, etc. , so that developers can analyze the advertising effect according to the data, so as to adjust the delivery strategy in time.

Developers can implement their own report display effects based on the returned data

So how do you get traffic monetization data? The following are the specific integration steps.

one. Get client ID and secret

Before obtaining the monetization data, we must first have the OAuth 2.0 client ID and key, which is used to generate the access_token when calling the report API. It should be noted that the client ID and key here do not refer to APPGallery Connect. The client ID of the application, but the client ID of the server application created in HUAWEI Developer -> Credentials.

  1. Register as a developer and complete real-name authentication. Log in to HUAWEI Developer , click "Administration Center" in the upper right corner to enter the main page.

  1. Go to the "Certificate" page and create a project. If there is an existing project, please skip [Step a].

a. Select "Certificate", and fill in "Project Name" and "Project Alias" according to the marked order in the following figure to create a new project.

b. Select the created project and click OK.

  1. Select "OAuth 2.0 Client ID" to create a client ID.

illustrate:

If the "OAuth 2.0 Client ID" credential already exists under the project, you need to check whether the product type is a server application. If it is a server application, you can skip [Step 4].

Checking method: Click the "Edit" button under the operation column to view the "Product Type".

If it is not of type "Server Application", you need to recreate the "OAuth 2.0 Client ID":

  1. Select "Server Application", enter "Product Name", select "Application Type" and "Default Language", click "Create"; prompt "Client ID" and "Key", click "OK".

  1. Go to the "My API" page, confirm the selected items, and click "Apply for a new HMS API service".

  1. Scroll down to find "App Services" and click "Data Monetization Service Report API".

  1. Click "Enable" to enable the traffic monetization service report API, and then you can call the traffic monetization report API.

After "disabled", when "enabled" again, due to page caching and other reasons, the effective time is not real-time effective, and it takes about 6 to 10 minutes to wait. If it doesn't work after 10 minutes, try again.

two. Call the traffic monetization report API

  1. Before calling the traffic monetization report API, you need to obtain the access_token authentication information.

Call interface:

POST https://oauth-login.cloud.huawei.com/oauth2/v3/token

Request example:

 POST /oauth2/v3/token HTTP/1.1
Host: oauth-login.cloud.huawei.com
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&
        client_id=<客户端ID >&
        client_secret=<客户端密钥>

Request sample screenshot:

It should be noted that the client ID and key are the client ID and key of the server application obtained in the developer alliance interface, not the client ID and key of the mobile application created in APPGallery Connect.

  1. After obtaining the access_token authentication information, call the report API.

Call interface:

POST https://ads.cloud.huawei.com/openapi/monetization/reports/v1/publisher

Russian sites need to call the following interfaces:

POST https://ads-drru.cloud.huawei.ru/openapi/monetization/reports/v1/publisher
Request example:

 POST /openapi/monetization/reports/v1/publisher HTTP/1.1
Content-Type: application/json
Authorization: Bearer ***
        Accept: application/json
Content-Length: 233

{
    "start_date": "2022-06-01",
    "end_date": "2022-06-28",
    "filtering": {
        "currency": "CNY"
    },
    "time_granularity": "STAT_TIME_GRANULARITY_DAILY",
    "page": 1,
    "page_size": 10
}

Request sample screenshot:

As you can see from the screenshot, the data has been returned successfully. For specific request parameters and response parameters, please refer to the documentation link

After calling the API to obtain the monetization report data, the developer can realize the presentation form of the data according to their own needs.

three. Common problems when accessing the traffic monetization report

Access forbidden is returned when calling the traffic monetization service report API?

Cause Analysis:

1. In the "API" column of the developer alliance interface, the API switch of the traffic monetization report for the corresponding project is not enabled.

2. After the traffic report API switch is "enabled", the report API interface is called before the permission takes effect.

3. When obtaining the access_token authentication information, the incoming client ID and key are not the ID and key of the server application in the "credentials" of the developer alliance interface.

Solution:

  1. Turn on the traffic report API switch, go to the developer alliance interface -> My API -> select the corresponding project -> click "Apply for a new HMS API service", find the "traffic monetization service report API" permission, and click "enable".

  2. After the traffic report API switch is "disabled", when it is "enabled" again, it does not take effect in real time, and it takes about 6 to 10 minutes.
  3. Check whether the incoming client ID is applied by the server when obtaining the access_token authentication information. In the developer alliance interface -> credentials -> find the corresponding project -> click the edit button of the application under the project, you can see the application type in the product type line. If it is not a server application, please change the client ID and key of the server application and try again.

Learn more details>>

Visit the official advertising service website

Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee

Follow us to know the latest technical information of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙应用,和开发者共同成长。