error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// AdWordsUser.php directly via require_once.
// $path = '/path/to/aw_api_php_lib/src';
$path = dirname(__FILE__) . '/../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once 'Google/Api/Ads/AdWords/Util/ReportUtils.php';
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the AdGroupAdService.
$adGroupAdService = $user->GetAdGroupAdService('v201101');
// $adGroupId = (float) '';
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignName', 'AdGroupName', 'Headline', 'Description1', 'Description2');
$selector->ordering = array(new OrderBy('Id', 'ASCENDING'));
// Amended predicates.
$adGroupIdPredicate = new Predicate('AdGroupId', 'IN');
// By default disabled ads aren't returned by the selector. To return them
// include the DISABLED status in a predicate.
$statusPredicate =new Predicate('Status', 'IN', array('ENABLED'));
//Amended Line
$selector->predicates = array($statusPredicate);
// Get all ads.
$page = $adGroupAdService->get($selector);
// Display ads.
if (isset($page->entries)) {
foreach ($page->entries as $adGroupAd) {
printf("Ad with id '%s', type '%s', and status '%s' was found.\n<br>",
$adGroupAd->ad->id, $adGroupAd->ad->AdType, $adGroupAd->status);
}
}
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'AD performance report #' . time();
$reportDefinition->reportType = 'AD_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
$reportDefinition->selector = $selector;
// Create operations.
$operation = new ReportDefinitionOperation();
$operation->operand = $reportDefinition;
$operation->operator = 'ADD';
$operations = array($operation);
// Add report definition.
$result = $reportDefinitionService->mutate($operations);
// Display report definitions.
if ($result != null) {
foreach ($result as $reportDefinition) {
printf("Report definition with name '%s' and id '%s' was added.\n",
$reportDefinition->reportName, $reportDefinition->id);
$reportDefinitionId = $reportDefinition->id;
$fileName = 'tv_g_ppc_ad_data.csv';
$path = dirname(__FILE__) . '/data/' . $fileName;
// Download report.
ReportUtils::DownloadReport($reportDefinitionId, $path, $user);
printf("Report with definition id '%s' was downloaded to '%s'.\n",
$reportDefinitionId, $path, $fileName);*/
}
}
else {
print "No ads were found.\n";
}
} catch (Exception $e) {
print $e->getMessage();
}