AdWords API PHP - 点击效果报告

时间:2014-05-15 21:07:22

标签: php adwords-apiv201402

我正在尝试从AdWords-API下载点击效果报告。对于我的例子,我只选择日期字段。

function DownloadCriteriaReportExample(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('Date');

  // Filter out deleted criteria.
  $selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));

  // Create report definition.
  $reportDefinition = new ReportDefinition();
  $reportDefinition->selector = $selector;
  $reportDefinition->reportName = 'Criteria performance report #' . uniqid();
  $reportDefinition->dateRangeType = 'YESTERDAY';
  $reportDefinition->reportType = 'CLICK_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, 'returnMoneyInMicros' => TRUE);

  // Download report.
  ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);

  printf("Report with name '%s' was downloaded to '%s'.\n",
      $reportDefinition->reportName, $filePath);
}

我得到的错误是:“ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT”。 对于标准性能报告,运行相同的脚本没有任何问题。

https://developers.google.com/adwords/api/docs/appendix/reports#click

3 个答案:

答案 0 :(得分:1)

问题在于您的谓词 - AS“点击效果报告”没有“状态”字段 - 因此请删除该谓词 - 这很可能是您的问题 -

也删除了 $ reportDefinition-> includeZeroImpressions = FALSE; 您不需要这个,因为这是一个点击效果报告 -

并且日期字段是一个段 - 如果以上不起作用,那么可能尝试添加至少一个属性,如GclId或其他东西 -

由于此报告只能运行一天,因此选择日期似乎很愚蠢。

希望这有帮助 -

请参阅此链接以了解报告字段 - 如果您计划运行各种报告,您会发现此链接非常有用

https://developers.google.com/adwords/api/docs/appendix/reports#click

答案 1 :(得分:0)

在错误之后是否有更多信息,例如Trigger =' status'或者其他的东西?这通常会告诉您导致错误的列。

如果这没有用,那么运行GetReportFields.php文件以查看名称列表并检查它们是否与您尝试使用的名称相匹配。

此外,名称在版本之间也会发生变化,因此它们显示的示例可能只有v201402版本的名称,并且您可能正在尝试v201309版本。我有这个问题,一旦我使用了新的库,它就被修复了。

答案 2 :(得分:0)

来自点击效果报告(https://developers.google.com/adwords/api/docs/appendix/reports/click-performance-report)的文档:

"注意:此报告只能在一天内运行,且仅适用于请求之前最多90天的日期。"

所以,我想你不能选择日期字段,因为它必须由你必须过滤的单个日期隐含。

我知道它已经很晚了,你可能已经开始了,但也许这会帮助其他人解决同样的问题。