簡體   English   中英

多個報告下載php adwords api

[英]multiple report download php adwords api

Iam嘗試下載“我的客戶中心”帳戶下各個子帳戶的報告。 我要在代碼中設置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());
}

您也可以這樣使用(AdWords Api版本:v201502)

$user = new AdWordsUser(NULL, NULL, NULL, NULL, NULL, NULL, $oauth2Info);
$user->SetClientCustomerId($clientCustomerId);
$user->LogAll();

我通常在實例化用戶時傳遞客戶ID。 該代碼來自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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM