Publisher Service Channel Report API(流量变现服务分渠道报表API)是广告服务向您提供的一套接口服务。您可以通过接入分渠道报表API,获取应用在不同渠道下的变现报表数据,包括请求量、返回量、展示率、点击率、收益占比等,实现高效的分渠道数据监控。
广告请求时传入了分渠道参数,同时产生了有效的广告事件。分渠道参数的传入,请参考开发者自定义参数分渠道能力。
当您需要获取应用分渠道变现数据时,可以在其应用服务器上调用分渠道报表API获取报表数据。
| 承载协议 | HTTPS POST |
|---|---|
| 接口方向 | 客户端->流量变现分渠道报表服务器 |
| 接口URL | POST https://ads.cloud.huawei.com/openapi/monetization/reports/v1/channelReport 说明: 俄罗斯站点: POST https://ads-drru.cloud.huawei.ru/openapi/monetization/reports/v1/channelReport |
| 数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
Request Header
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| Content-Type | 是 | String | 取值为:application/json; charset=UTF-8 |
| Authorization | 是 | String | 请参见基于OAuth 2.0开放鉴权。 说明 Bearer后面拼接空格,再拼接获取的access_token。 |
Request Body
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| start_date | 是 | String | 起始日期,格式:yyyy-MM-dd。 |
| end_date | 是 | String | 结束日期,格式:yyyy-MM-dd。 |
| app_ids | 否 | String[] | 应用ID。 |
| bundles | 否 | String[] | 应用包名。 |
| group_by | 否 | String[] | 分组查看条件,仅支持按日期分组,即传入"STAT_BREAK_DOWNS_DATE" 如果传入分组条件,响应的数据将会按天的维度做区分呈现。 如果未传入分组条件,响应的数据将汇总呈现。 |
| page | 否 | Integer | 搜索页码。 取值范围:[1,1000],默认值1。 |
| page_size | 否 | Integer | 一页展示数量。 取值范围:[1,1000],默认值20。 |
| order_field | 否 | String | 排序字段。 所有的统计指标均可参与排序。 |
| order_type | 否 | String | 排序方式。 可取值为:“ASC”、"DESC",默认取值为DESC。 |
POST / openapi / monetization / reports / v1 / channelReport HTTP / 1.1
Content - Type: application / json
Authorization: Bearer * * *
Accept: application / json
Content - Length: 233 {
"start_date": "2024-03-20",
"end_date": "2024-06-20",
"group_by": ["STAT_BREAK_DOWNS_DATE"],
"page": 1,
"page_size": 10,
"order_field": "show_count",
"order_type": "DESC"
} Response Header
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| Content-Type | 是 | String | 取值为:application/json; charset=UTF-8 |
Response Body
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| page_info | 是 | struct | 分页配置信息,请参见page_info参数。 |
| list | 是 | struct | 统计数据列表,请参见list参数。 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| page | 是 | Integer | 搜索页码。 |
| page_size | 是 | Integer | 一页显示的数据条数。 |
| total_number | 是 | Integer | 总条数。 |
| total_page | 是 | Integer | 总页数。 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| app_id | 否 | String | 应用ID,当未根据应用进行分组时,该值无实际意义。 |
| channel_id | 否 | String | 渠道号,当未根据渠道号进行分组时,该值无实际意义。 |
| stat_datetime | 是 | String | 数据起始时间。 格式:yyyy-MM-dd。 |
| reached_ad_requests | 否 | Integer | 广告请求量。 |
| matched_reached_ad_requests | 否 | Integer | 广告返回量。 |
| show_count | 否 | Integer | 展示量。 |
| click_count | 否 | Integer | 点击量。 |
| ad_requests_match_rate | 否 | float | 填充率。 |
| ad_requests_show_rate | 否 | float | 展示率。 |
| click_through_rate | 否 | float | 点击率。 |
| earning_rate | 否 | float | 预估收益占比。 |
HTTP / 1.1 200 OK
Content - type: application / json
content - length: 2381 {
"code": "0",
"message": "OK",
"data": {
"page_info": {
"page": 1,
"page_size": 1,
"total_number": 1,
"total_page": 1
},
"list": [{
"app_id": "1111111",
"channel_id": "1",
"stat_datetime": "2024-05-01",
"earnings": 30.8,
"reached_ad_requests": 100,
"matched_reached_ad_requests": 90,
"show_count": 154,
"click_count": 14,
"ad_requests_match_rate": 0.8256,
"ad_requests_show_rate": 0.2121,
"click_through_rate": 0.2141,
"earning_rate": 0.2141
}
]
}
} 使用开发者联盟界面获得的client_id以及对应密钥,发送HTTPS POST请求,获取查询access_token。
样例代码(Java)如下:
其中tokenUrl = "https://oauth-login.cloud.huawei.com/oauth2/v3/token"。
/**
* 获取token信息
*
* @return 返回token值
* @throws IOException 异常
*/
private static String getOauthToken() throws IOException {
// 设置报文头 Content-Type
PostMethod postMethod = new PostMethod(tokenUrl);
postMethod.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded;charset=utf-8");
// 设置报文body
List < NameValuePair > param = new ArrayList < > ();
param.add(new NameValuePair("grant_type", "client_credentials"));
param.add(new NameValuePair("client_id", clientId));
param.add(new NameValuePair("client_secret", secret));
postMethod.setRequestBody(param.toArray(new NameValuePair[param.size()]));
HttpClient httpClient = new HttpClient();
int ret = httpClient.executeMethod(postMethod);
String accessToken = null;
String tokenResponse = postMethod.getResponseBodyAsString();
if (ret == 200) {
JSONObject atJson = JSONObject.parseObject(tokenResponse);
accessToken = atJson.getString("access_token");
} else {
System.out.println("request access token failed " + tokenResponse);
}
return accessToken;
} 通过以上步骤获取的access_token信息,发送HTTPS POST查询报表数据。
样例代码(Java)如下:
其中reportUrl = "https://ads.cloud.huawei.com/openapi/monetization/reports/v1/channelReport "。
/**
* 调用报表查询接口
* @param accessToken 根据clientId 和密钥获取的token
* @throws IOException
*/
private static void callApiUseToken(String accessToken) throws IOException {
// 设置报文头 Content-Type, Authorization
PostMethod postMethod = new PostMethod(reportUrl);
postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");
postMethod.setRequestHeader("Authorization","Bearer " + accessToken);
// 设置报文body
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("start_date", "2024-05-01");
bodyMap.put("end_date", "2024-06-20");
bodyMap.put("order_field", "show_count");
bodyMap.put("order_type", "DESC");
RequestEntity requestEntity = new StringRequestEntity( JSONObject.toJSONString(bodyMap),
"application/json" ,"UTF-8");
postMethod.setRequestEntity(requestEntity);
HttpClient httpClient = new HttpClient();
int ret = httpClient.executeMethod(postMethod);
String rpsContent = postMethod.getResponseBodyAsString();
if (ret == 200) {
System.out.println(rpsContent);
} else {
System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);
}
}