[英]multiple report download php adwords api
Iam trying to download a reports for various sub-accounts under an MCC account. Iam尝试下载“我的客户中心”帐户下各个子帐户的报告。 I am setting the clientCustomerId from within my code since I would want to loop through the various clientCustomerIds to have all the reports downloaded in one run.
我要在代码中设置clientCustomerId,因为我想遍历各种clientCustomerId,以一次下载所有报告。 So far I have been testing it with one clientCustomerId but I get the following error:
到目前为止,我已经使用一个clientCustomerId对其进行了测试,但是出现以下错误:
An error has occurred: The client customer ID must be specified for report downloads. 发生错误:必须为报告下载指定客户端客户ID。
I have no idea where I am going wrong. 我不知道我要去哪里错了。 I am using AdWords API v201406:
我正在使用AdWords API v201406:
Here is the code: 这是代码:
<?php
require_once dirname(dirname(__FILE__)) . '/init.php';
require_once ADWORDS_UTIL_PATH . '/ReportUtils.php';
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $filePath the path of the file to download the report to
*/
function KeywordPerformanceReport(AdWordsUser $user, $filePath) {
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('AccountDescriptiveName', 'CampaignId', 'CampaignName', 'CampaignStatus', 'AdGroupId', 'AdGroupName', 'AdGroupStatus',
'AverageCpc', 'AveragePageviews', 'AverageTimeOnSite', 'Id', 'Impressions', 'KeywordText', 'Clicks', 'PlacementUrl', 'TrackingUrlTemplate', 'ConversionRate', 'Conversions', 'Cost', 'Date', 'DayOfWeek', 'DestinationUrl');
// Filter out removed criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('REMOVED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Keyword performance report #' . time();
$reportDefinition->dateRangeType = 'YESTERDAY';
$reportDefinition->reportType = 'KEYWORDS_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = FALSE;
// Set additional options.
$options = array('version' => ADWORDS_VERSION);
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n",
$reportDefinition->reportName, $filePath);
}
// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
return;
}
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
$customerId='xxx-xxx-xxx';
$user->SetClientId($customerId);
// Log every SOAP XML request and response.
$user->LogAll();
// Download the report to a file in the same directory as the example.
$filePath = dirname(__FILE__) . '/report.csv';
// Run the example.
KeywordPerformanceReport($user, $filePath);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
You can also use like this (Adwords Api Version : v201502) 您也可以这样使用(AdWords Api版本:v201502)
$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $oauth2Info);
$user->SetClientCustomerId($clientCustomerId);
$user->LogAll();
I normally pass the customer id in when instantiating the user. 我通常在实例化用户时传递客户ID。 This code is from v201402.
该代码来自v201402。
$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $customerID);
请使用SetClientCustomerId()
函数从多个帐户获取数据,该API在以前版本的API中受支持,而现在, withClientCustomerId()
提供了AdWordsSessionBuilder
withClientCustomerId()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.