class DownloadCriteriaReportWithSelector {
public static function runExample(AdWordsSession $session, $filePath) { // Create selector. $selector = new Selector(); $selector->setFields(['CampaignId']);
// Use a predicate to filter out paused criteria (this is optional). $selector->setPredicates([ new Predicate('Status', PredicateOperator::NOT_IN, ['PAUSED'])]);
// Create report definition. $reportDefinition = new ReportDefinition(); $reportDefinition->setSelector($selector); $reportDefinition->setReportName( 'Criteria performance report #' . uniqid()); $reportDefinition->setDateRangeType( ReportDefinitionDateRangeType::LAST_7_DAYS); $reportDefinition->setReportType( ReportDefinitionReportType::CRITERIA_PERFORMANCE_REPORT); $reportDefinition->setDownloadFormat(DownloadFormat::CSV);
// Download report. $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->downloadReport( $reportDefinition, $reportSettingsOverride); $reportDownloadResult->saveToFile($filePath); printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->getReportName(), $filePath); }
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();
$filePath = sprintf( '%s.csv', tempnam(sys_get_temp_dir(), 'criteria-report-') ); self::runExample($session, $filePath); }}
DownloadCriteriaReportWithSelector::main();
Dominiks-iMac:adwords Dominik$ php DownloadCriteriaReportWithSelector.php
[2018-02-12 12:22:51] AW_REPORT_DOWNLOADER.WARNING: clientCustomerId=608-580-1167 ###### (AwApi-PHP, googleads-php-lib/32.1.0, PHP/7.1.11, GuzzleHttp/6.2.1, curl/7.45.0) "POST /api/adwords/reportdownload/v201710 HTTP/1.1" Status: 400
[2018-02-12 12:22:51] AW_REPORT_DOWNLOADER.NOTICE: Request:
POST /api/adwords/reportdownload/v201710 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: adwords.google.com
Authorization: REDACTED
developerToken: REDACTED
clientCustomerId: #########
User-Agent: ######## (AwApi-PHP, googleads-php-lib/32.1.0, PHP/7.1.11, GuzzleHttp/6.2.1, curl/7.45.0)
skipReportHeader: false
skipColumnHeader: false
skipReportSummary: false
useRawEnumValues: false
includeZeroImpressions: false
__rdxml=<?xml version="1.0"?>
<reportDefinition><selector><fields>CampaignId</fields><predicates><field>Status</field><operator>NOT_IN</operator><values>PAUSED</values></predicates></selector><reportName>Criteria performance report #5a81790a0c817</reportName><reportType>CRITERIA_PERFORMANCE_REPORT</reportType><dateRangeType>LAST_7_DAYS</dateRangeType><downloadFormat>CSV</downloadFormat></reportDefinition>
Response:
REDACTED REPORT DATA
--------
Error:
Client error: `POST https://adwords.google.com/api/adwords/reportdownload/v201710` resulted in a `400 Bad Request` response
PHP Fatal error: Uncaught Google\AdsApi\AdWords\v201710\cm\ApiException: Details: [fieldPath: selector.reportDefinition; trigger: ; errorString: ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH] in /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php:168
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php(106): Google\AdsApi\AdWords\Reporting\v201710\ReportDownloader->makeReportRequest(Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/DownloadCriteriaReportWithSelector.php(68): Google\AdsApi\AdWords\Reporting\v201710\ReportDownloader->downloadReport(Object(Google\AdsApi\AdWords\Reporting\v201710\ReportDefinition), Object(Google\AdsApi\AdWords\ReportSettings))
#2 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/DownloadCriteriaReportWithSelector.php(93): Google\AdsApi\Examples\AdWords\v201710\Reporting\DownloadCriteriaReportWithSel in /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php on line 168
Fatal error: Uncaught Google\AdsApi\AdWords\v201710\cm\ApiException: Details: [fieldPath: selector.reportDefinition; trigger: ; errorString: ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH] in /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php:168
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php(106): Google\AdsApi\AdWords\Reporting\v201710\ReportDownloader->makeReportRequest(Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/DownloadCriteriaReportWithSelector.php(68): Google\AdsApi\AdWords\Reporting\v201710\ReportDownloader->downloadReport(Object(Google\AdsApi\AdWords\Reporting\v201710\ReportDefinition), Object(Google\AdsApi\AdWords\ReportSettings))
#2 /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/DownloadCriteriaReportWithSelector.php(93): Google\AdsApi\Examples\AdWords\v201710\Reporting\DownloadCriteriaReportWithSel in /Applications/XAMPP/xamppfiles/htdocs/crm/adwords/googleads-php-lib/src/Google/AdsApi/AdWords/Reporting/v201710/ReportDownloader.php on line 168
How can i solve this?
PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' in /usr/share/nginx/www/adwords/googleads-php-lib/vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.php on line 59