Here is my code :
public static function runExample(AdWordsServices $adWordsServices,
AdWordsSessionBuilder $sessionBuilder, $reportDir, $CampaignName,
$FromDate, $ToDate) {
// Construct an API session for the client customer ID specified in
the
// configuration file.
$session = $sessionBuilder->build();
// Create selector.
$selector = new Selector();
$selector->setFields(
['CampaignId', 'CampaignName', 'AdGroupId', 'Impressions',
'Clicks', 'Cost']);
$selector->setPredicates([
new Predicate('CampaignName', PredicateOperator::IN,
[$CampaignName])]);
// $dateRange = new DateRange();
// $dateRange->min = $FromDate;
// $dateRange->max = $ToDate;
// $selector->dateRange = $dateRange;
$selector->setDateRange(new DateRange($FromDate, $ToDate));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->setSelector($selector);
$reportDefinition->setReportName('Custom
ADGROUP_PERFORMANCE_REPORT');
$reportDefinition->setDateRangeType(
ReportDefinitionDateRangeType::CUSTOM_DATE);
$reportDefinition->setReportType(
ReportDefinitionReportType::ADGROUP_PERFORMANCE_REPORT);
$reportDefinition->setDownloadFormat(DownloadFormat::XML);
$customerIds = self::getAllManagedCustomerIds($adWordsServices,
$session);
printf("Downloading reports for %d managed customers.\n",
count($customerIds));
$successfulReports = [];
$failedReports = [];
foreach ($customerIds as $customerId) {
// $filePath = sprintf('%s%sadgroup_%d.xml', $reportDir,
DIRECTORY_SEPARATOR, $customerId);
$filePath = dirname(__FILE__) . '/report.xml';
// Construct an API session for the specified client customer
ID.
$session =
$sessionBuilder->withClientCustomerId($customerId)->build();
$reportDownloader = new ReportDownloader($session);
$retryCount = 0;
$doContinue = true;
do {
$retryCount++;
try {
$reportDownloadResult =
$reportDownloader->downloadReport($reportDefinition);
// echo '<pre>';
// print_r($reportDownloadResult);
// echo '</pre>';
$reportDownloadResult->saveToFile($filePath);
printf(
"Report for client customer ID %d successfully
downloaded to: "
. "%s\n", $customerId, $filePath
);
$successfulReports[$customerId] = $filePath;
$doContinue = false;
} catch (ApiException $e) {
printf(
"Report attempt #%d for client customer ID %d
was not downloaded"
. " due to: %s\n", $retryCount, $customerId,
$e->getMessage()
);
// If this is a server error, retry up to the defined
maximum number
// of retries.
if ($e->getErrors() === null && $retryCount <
self::MAX_RETRIES) {
$sleepTime = $retryCount * self::BACKOFF_FACTOR;
printf(
"Sleeping %d seconds before retrying report
for client customer"
. " ID %d.\n", $sleepTime, $customerId
);
sleep($sleepTime);
} else {
printf(
"Report request failed for client customer
ID %d.\n", $customerId
);
$failedReports[$customerId] = $filePath;
$doContinue = false;
}
}
} while ($doContinue === true);
}
$doc = new DOMDocument();
$doc->loadXML(file_get_contents($filePath));
$xp = new DOMXPath($doc);
$q = $xp->query("/report/table/row/@cost");
$r = $xp->query("/report/table/row/@impressions");
$s = $xp->query("/report/table/row/@clicks");
$cost = 0.00;
foreach ($q as $el) {
$v = $el->textContent;
$cost += $v / 1000000;
}
$click = 0;
foreach ($s as $el) {
$v = $el->textContent;
$click += $v;
}
$impressions = 0;
foreach ($r as $el) {
$v = $el->textContent;
$impressions += $v;
}
echo "$cost|$impressions|$click";
print "All downloads completed. Results:\n";
print "Successful reports:\n";
foreach ($successfulReports as $customerId => $filePath) {
printf("\tClient ID %d => '%s'\n", $customerId, $filePath);
}
print "Failed reports:\n";
foreach ($failedReports as $customerId => $filePath) {
printf("\tClient ID %d => '%s'\n", $customerId, $filePath);
}
print "End of results.\n";
}
Here is the error message in error log :
PHP Fatal error: Class
'Google\\AdsApi\\Examples\\AdWords\\v201705\\Reporting\\DOMDocument' not
found in /****************/newGoogleAds01/vendor/ParallelReportDownload.php
I have installed php-xml and this used to work when I was using it with
v201609
Please help me out.
Thanx
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/ed5eb525-085c-4ca8-8a73-a0ae93c30352%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.