Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多报表下载php adwords api_Php_Google Ads Api - Fatal编程技术网

多报表下载php adwords api

多报表下载php adwords api,php,google-ads-api,Php,Google Ads Api,Iam正在尝试下载MCC帐户下各子帐户的报告。我在我的代码中设置clientCustomerId,因为我想循环各种clientCustomerId,以便在一次运行中下载所有报告。到目前为止,我一直在使用一个clientCustomerId对其进行测试,但我发现以下错误: 出现错误:必须为报表下载指定客户端客户ID 我不知道我哪里出错了。我使用的是AdWords API v201406: 代码如下: <?php require_once dirname(dirname(__FILE__))

Iam正在尝试下载MCC帐户下各子帐户的报告。我在我的代码中设置clientCustomerId,因为我想循环各种clientCustomerId,以便在一次运行中下载所有报告。到目前为止,我一直在使用一个clientCustomerId对其进行测试,但我发现以下错误:

出现错误:必须为报表下载指定客户端客户ID

我不知道我哪里出错了。我使用的是AdWords API v201406:

代码如下:

<?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());
}

我通常在实例化用户时传入客户id。此代码来自v201402

$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $customerID);

您也可以这样使用(Adwords Api版本:v201502)


使用函数
SetClientCustomerId()
从多个帐户获取数据,这在以前版本的API中是受支持的,现在
AdWordsSessionBuilder
中有了clientCustomerId()
这可能是个愚蠢的问题,但我假设您使用的是来自MCC的实际cusomterId,其中有“xxx xxx xxx xxx”?您看过记录的soap请求了吗?
$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $oauth2Info);
$user->SetClientCustomerId($clientCustomerId);
$user->LogAll();