public static function runExample(AdWordsSession $session, $reportFormat)
{
// Create report query to get the data for last 7 days.
$reportQuery = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, '
. 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT '
. 'WHERE Status IN [ENABLED, PAUSED] DURING LAST_7_DAYS';
// Download report as a string.
$reportDownloader = new ReportDownloader($session);
// Optional: If you need to adjust report settings just for this one
// request, you can create and supply the settings override here. Otherwise,
// default values from the configuration file (adsapi_php.ini) are used.
$reportSettingsOverride = (new ReportSettingsBuilder())
->includeZeroImpressions(false)
->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql($reportQuery, $reportFormat, $reportSettingsOverride);
self::$report = $reportDownloadResult->getAsString();
self::$status = "success";
self::$message = "";
}
public static function main()
{
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
// See: AdWordsSessionBuilder for setting a client customer ID that is
// different from that specified in your adsapi_php.ini file.
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
try {
self::runExample($session, DownloadFormat::CSV);
} catch (\Exception $e) {
return array(
"status" => "fail",
"message" => $e->getMessage()
);
}
return array(
"status" => self::$status,
"report" => self::$report,
);
}