Good morning for all,
I did the following code:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('APPLICATION_PATH',realpath(dirname(__FILE__) . DS));
require_once APPLICATION_PATH . '/../library/Google/Api/Ads/AdWords/
Lib/AdWordsUser.php';
require_once APPLICATION_PATH . '/../library/Google/Api/Ads/AdWords/
Util/ReportUtils.php';
require_once APPLICATION_PATH . '/../library/Google/Api/Ads/AdWords/
v201008/ReportDefinitionService.php';
class ReportController {
private $adwordsUser;
private function
getReportDefinitionForAccountPerformanceReport(ReportDefinitionService
$reportDefinitionService){
$reportType = 'ACCOUNT_PERFORMANCE_REPORT';
$reportDefinitionFields = $reportDefinitionService-
>getReportFields($reportType);
$fieldsBlockeds = array(
'ConversionCategoryName',
'ConversionTypeName',
'ClickType',
'BudgetLostImpressionShare',
'Device',
'ExactMatchImpressionShare',
'HourOfDay',
'ImpressionShare',
'QualityLostImpressionShare'
);
$fields = array();
foreach($reportDefinitionFields as $field)
if(!in_array($field->fieldName,$fieldsBlockeds))
$fields[] = $field->fieldName;
$selector = new Selector();
$selector->fields = $fields;
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = $reportType . ' ' . time();
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = $reportType;
$reportDefinition->downloadFormat = 'XML';
$reportDefinition->selector = $selector;
return (object) $reportDefinition;
}
private function getAllReportDefinition(ReportDefinitionService
$reportDefinitionService){
// Create selector.
$selector = new ReportDefinitionSelector();
// Get all report definitions.
$page = $reportDefinitionService->get($selector);
// Display report definitions.
if (isset($page->entries)) {
foreach ($page->entries as $reportDefinition) {
printf("ReportDefinition with name '%s' and id
'%s' was found.\n
<br>", $reportDefinition->reportName, $reportDefinition->id);
}
} else {
print "No report definitions were found.\n";
}
}
public function downloadReport($pathFileName,$reportDefinitionId){
ReportUtils::DownloadReport($reportDefinitionId, $pathFileName,
$this->adwordsUser);
}
public function addReport($reportDefinition){
$operation = new ReportDefinitionOperation();
$operation->operand = $reportDefinition;
$operation->operator = 'ADD';
$operations = array($operation);
$result = $reportDefinitionService->mutate($operations);
return $result;
}
public function removeReport($reportDefinitionId){
$reportDefinition = new ReportDefinition();
$reportDefinition->id = $reportDefinitionId;
$operation = new ReportDefinitionOperation();
$operation->operand = $reportDefinition;
$operation->operator = 'REMOVE';
$operations = array($operation);
$result = $reportDefinitionService->mutate($operations);
return $result;
}
public function __construct() {
try {
$email = '[email protected]';
$pass = 'password';
$serviceVersion = 'v201101';
$userAgent = 'PHP Dynamo';
$developerToken = 'Djid_AAABBCCCDD';
//$developerToken =
'[email protected]++BRL';
$clientID = '000-000-0000';
//$clientID =
'[email protected]';
$serverData = 'https://adwords.google.com';
//$serverData = 'https://adwords-sandbox.google.com';
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$this->adwordsUser = new AdWordsUser(null,$email,$pass,
$developerToken,$userAgent,$clientID);
// Log SOAP XML request and response.
$this->adwordsUser->LogDefaults();
$reportDefinitionService = $this->adwordsUser-
>GetReportDefinitionService($serviceVersion,$serverData);
$reportDefinition = $this-
>getReportDefinitionForAccountPerformanceReport($reportDefinitionService);
$this->getAllReportDefinition($reportDefinitionService);
$reportDefinitionId = (float) '143533360';
$pathFileName = APPLICATION_PATH .
'/reportsDownloads/report'.
$reportDefinitionId.'.xml';
$this->downloadReport($pathFileName,$reportDefinitionId);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
// this is a instance of this class
$reportController = new ReportController();
?>
But the error persists INVALID_REPORT_DEFINITION_ID.
Help me please.
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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