изтегляне на множество отчети 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

Обикновено предавам идентификатора на клиента, когато създавам потребителя. Този код е от v201402.

$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