[Huawei Developers] Mike-mei:
View attachment 5665129

Ads are everywhere and we can't escape them. They're on road billboards, shops, buses and buildings. If a world filled with ads sounds daunting and you want to hide indoors, just beware that ads will even jump out at you from your TV, computer, or phone.

It's likely that ads will be around with us for forever. Ads are often seen as annoying, but they can in fact be very helpful. If you are looking for a job, want to go somewhere fun, or are not sure what special thing you can get for your other half's birthday, ads may in fact provide some inspiration to you.

Nowadays, ads are transforming in appearance and purpose. Ads are becoming more intuitive as they are able to target specific audiences. For example, ads about quick fashion will target young adults, while some ads are typically pushed to males. This is an advanced advertising mechanism for brands, media, and users, where all can benefit. Someone gets traffic, someone makes money, and someone gets what they needed. Under ideal conditions, ads, under control and without harmful information spread, mean a lot for us.

As an app developer, I have been trying for a long time to request ads in my app to monetize the traffic and increase revenue. Recently, I encountered some obstacles with the ad traffic monetization data of my own app, and I have been searching for tools to obtain data and analyze ad performance. Collecting such data and then deciding how to analyze ad performance was no easy task, and this was complicated by the many tools and plugins needed to do so. I have used some of the tools found in the industry, but their performance rarely satisfied me.

But I eventually came across a very useful tool, the Publisher Service Reporting API of Ads Kit provided by HMS Core. The traffic monetization service helps me display various ad formats, such as banners, native ads, and rewarded ads, to my users. Routine data tracking is crucial for me to boost revenue. What's more, the Reporting API is key to obtaining ad monetization data, including ad requests, returned ads, impression rate, and click-through rate. I can analyze ad performance based on this data and adjust my monetization strategies accordingly.

But how did I acquire traffic monetization data? Here I'll tell you how I did it.

Implementation Procedure​

1. Obtain the client ID and key.

Before obtaining the monetization data, prepare an OAuth 2.0 client ID and key, which are needed for generating the access token passed for calling the Reporting API.

Note that the client ID and key are not those in App information (shown in the following red box) in AppGallery Connect, instead, the client ID and key of the server app created under HMS API services > Credentials on HUAWEI Developers.

View attachment 5665131

a. Register as a developer and complete identity verification.

View attachment 5665133

b. Sign in to the console, choose HMS API Services > Credentials, and create a project. If you already have a project, directly select it.

Click the drop-down arrow at the top, click New project, fill in the project name and alias, and click OK.

View attachment 5665189

Select the project you created and click OK.

View attachment 5665191

c. Choose OAuth 2.0 client ID.

View attachment 5665193

If an OAuth 2.0 client ID and key already exist in your project, you can check whether the product type is server app by clicking Edit in the Operation column of the project. If so, skip step d.

View attachment 5665197

If your product is not a server app, you should create an OAuth 2.0 client ID.

View attachment 5665199

d. Select Server app from Product type, set Product name, App type, and Default language, and click Create. In the Note dialog box that displays Client ID and Key, click Confirm.

View attachment 5665201

e. Go to HMS API services > My APIs, ensure that the project is the one you created, and click Add API from library.

View attachment 5665203

f. Click Publisher Service Reporting API under App Services.

View attachment 5665205

g. On the page displayed, click Enable to enable the API. Then you can call the API.

View attachment 5665207

If you disable it and then enable it again, the setting does not take effect in real time due to page cache, for example. The setting will take about 6 to 10 minutes to take effect. If you have waited for longer time, try again.

2. Call the Publisher Service Reporting API.

a. Obtain an access token.

Call this API:

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=<Client ID>&
client_secret=<Client secret>

Screenshot:

View attachment 5665209

Note that again: the client ID and key are those of the server app but not those of the mobile app created.

b. Call the Reporting API.

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

If you are in Russia, call this API:

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
}

Screenshot:

View attachment 5665211

As shown in the preceding figure, the data is successfully returned. For more request parameters and response parameters, click here.

In addition, I can customize data display formats to suit my specific app scenarios.

Some Problems You May Encounter​

Why was message "access forbidden" returned during the API calling?

View attachment 5665215

Some Problems You May Encounter​

Why was message "access forbidden" returned during the API calling?

View attachment 5665221

Possible causes:

You have not enabled the Reporting API.

You have not been authorized to call this API, or your permission has not taken effect yet.

The client ID and key used for obtaining the access token are not those of your server app.

My solutions:

1. Click Add API from library under My APIs and enable the Reporting API.

View attachment 5665223View attachment 5665225View attachment 5665227

2. If you disabled and enabled the API again, you may need to wait for 6-10 minutes before the setting takes effect.

3. Check whether your client ID and key belong to a server app when you obtain the access token. To find out it, check the app type on the Credentials page. If it is not a server app, create one and use its client ID and key to request an access token.

View attachment 5665231

Conclusion​

If you also think obtaining ad monetization data and dealing with ad issues are annoying as me, you can try this tool to help you in daily work to obtain data and help you in subsequent operations. Hope that my procedure and experience can help more guys and you can also find out more useful methods.