загрузка нескольких отчетов php adwords api

Я пытаюсь загрузить отчеты для различных дочерних учетных записей в учетной записи Центра клиентов. Я устанавливаю clientCustomerId из своего кода, так как я хотел бы перебрать различные clientCustomerId, чтобы загрузить все отчеты за один запуск. До сих пор я тестировал его с одним clientCustomerId, но получаю следующую ошибку:

Произошла ошибка: для загрузки отчетов необходимо указать идентификатор клиента клиента.

Я понятия не имею, где я ошибаюсь. Я использую 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());
}

person Bob    schedule 24.10.2014    source источник
comment
Вероятно, это глупый вопрос, но я предполагаю, что вы используете фактический cusomterId из своего MCC, где у вас есть «xxx-xxx-xxx»? Вы видели зарегистрированный запрос на мыло?   -  person Stewart_R    schedule 27.10.2014


Ответы (3)


Вы также можете использовать это (версия Adwords Api: v201502)

$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $oauth2Info);
$user->SetClientCustomerId($clientCustomerId);
$user->LogAll();
person Vijaysinh Parmar    schedule 02.05.2015

Обычно я передаю идентификатор клиента при создании экземпляра пользователя. Этот код взят из версии 201402.

$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $customerID);
person Peter Bowen    schedule 30.10.2014

используйте функцию SetClientCustomerId() для получения данных из нескольких учетных записей, это поддерживалось в предыдущей версии API, которая теперь withClientCustomerId() присутствует в AdWordsSessionBuilder.

person Vivek Tiwari    schedule 05.04.2017