如何使用PHP SDK从AdmobMediation获取中介报告

时间:2019-04-23 10:30:22

标签: php google-api-php-client adsense-api mobile-ad-mediation

我正在使用google-api-php-client从我们的服务器远程获取AdmobMediation报告

一切正常,除了响应报告仅与“ Admob网络”有关,与“调解报告”无关

因此,指标不完整

所以我有两个问题:

1-是否可以使用SDK获取中介报告,而不仅仅是Admob广告联盟报告?

2-是否可以使用php SDK下载在“ Admob信息中心”上保存的报告?

非常感谢

$startDate = '2019-04-01';
$endDate = '2019-04-09';
$AppId = 'xxxx';
$accountId = 'xxxx';

/*
    Create the client
*/
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');

/*
    Authentication
*/
$client->setClientId('xxx');
$client->setClientSecret('xxx');
$client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob");
$refreshedAccessToken = $client->refreshToken('xxx');
$client->setAccessToken($refreshedAccessToken);

/*
    Create the service
*/
$service = new Google_Service_AdSense($client);


/*
    Get the result
*/
$metrics = array(
    'AD_REQUESTS', 'VIEWED_IMPRESSIONS', 'IMPRESSIONS_RPM', 'CLICKS', 'REACHED_AD_REQUESTS',
    'IMPRESSIONS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM', 'EARNINGS'
);
$filter = array(
    'APP_ID==' . $AppId
);
$optParams = array(
    'currency' => 'USD',
    'metric' => $metrics,
    'dimension' => 'DATE',
    'sort' => '+DATE',
    'filter' => $filter,
    'useTimezoneReporting'=>true
);
$result = $service->accounts_reports->generate($accountId, $startDate, $endDate, $optParams);