如何使用Google AdWords API获取所有广告系列的详细信息?

5
我可以使用Google AdWords API(使用测试账号)获取广告系列列表,我想使用API获取每个广告系列的所有详细信息(印象,点击量,预算,成本,CPC等)。如何实现? 尝试使用以下代码:
  // Get the service, which loads the required classes.
  $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('Id', 'Name','Impressions', 'Clicks');
  $selector->ordering[] = new OrderBy('Name', 'ASCENDING');

  // Create paging controls.
  $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  do {
    // Make the get request.
    $page = $campaignService->get($selector);

    // Display results.
    if (isset($page->entries)) {
      foreach ($page->entries as $campaign) {
        printf("Campaign with name '%s' and ID '%s' and Impressions %s was found.\n",
            $campaign->name, $campaign->id,$campaign->impressions);
      }
    } else {
      print "No campaigns were found.\n";
    }

    // Advance the paging index.
    $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);

但出现了这个错误:
An error has occurred: [SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Impressions', SelectorError.INVALID
_FIELD_NAME @ serviceSelector; trigger:'Clicks']

谢谢。

你能展示一下你尝试过什么吗?到目前为止,你是如何实现AdWords API的? - sotoz
1个回答

5

如果您想获取展示量、点击量和转化量等性能数据,则必须使用ReportingService。(不能使用CampaignService查询该信息) 使用ReportingService时,您需要使用CAMPAIGN_PERFORMANCE_REPORT。

https://developers.google.com/adwords/api/docs/appendix/reports/campaign-performance-report

我建议使用AWQL来进行查询,因为它与SQL非常相似。所以如果你熟悉SQL,那么理解起来非常容易。

https://developers.google.com/adwords/api/docs/guides/awql

以下是关于 PHP(CriteriaReport)的示例代码: https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201509/Reporting/DownloadCriteriaReportWithAwql.php


3
您可以使用https://www.awql.me 这个免费AWQL控制台轻松测试您的AWQL查询。 - bastien

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接