PHP Adwords API 获得升级的网址

PHP Adwords API get Upgraded URLs

我正在尝试通过 Adwords API 检索升级后的 URL,但我得到的只是 NULL。我使用的是最新版本的客户端库 (v201502) 这是我使用的代码

    $adGroupAdService = $this->oGAW->GetService('AdGroupAdService', ADWORDS_VERSION);

    $selector = new Selector();
    $selector->fields = array('AdGroupId');

    // Create predicates.
    $selector->predicates[] =
        new Predicate('AdGroupId', 'IN', array($adGroupId));
    $selector->predicates[] =
        new Predicate('AdType', 'IN', array('TEXT_AD', 'DYNAMIC_SEARCH_AD'));

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

    $page = $adGroupAdService->get($selector);

它 returns 这个

object(TextAd)[107]
  public 'headline' => string 'headline'
  public 'description1' => string 'description1' 
  public 'description2' => string 'description2'
  public 'id' => string '76813511440' (length=11)
  public 'url' => null
  public 'displayUrl' => string 'test.nl/test'
  public 'finalUrls' => null
  public 'finalMobileUrls' => null
  public 'finalAppUrls' => null
  public 'trackingUrlTemplate' => null
  public 'urlCustomParameters' => null
  public 'devicePreference' => null
  public 'AdType' => string 'TextAd' (length=6)
  private '_parameterMap' (Ad) => 
    array (size=1)
      'Ad.Type' => string 'AdType' (length=6)

我做错了什么?

谢谢!

我找到了解决方法,我现在使用 ReportDefinitionService 获取今天的 AD_PERFORMANCE_REPORT。

最终网址显示在 csv 中 returns。

$oAdwords = Utility_Adwords::getInstance($iCredentials);
$user = $oAdwords->getAdwordsUser($iCredentials, $iCustomerId);
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION_SPEND);

// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignId', 'CampaignName','CampaignStatus', 'AdGroupId', 'Id', 'AdGroupName', 'AdGroupStatus',  'Status', 'AdType', 'DisplayUrl', 'CreativeDestinationUrl', 'CreativeFinalUrls', 'CreativeTrackingUrlTemplate', 'CreativeUrlCustomParameters');

// Filter out removed criteria.
$selector->predicates[] = new Predicate('CampaignId', 'IN', $aCampaigns);
$selector->predicates[] = new Predicate('AdGroupStatus', 'NOT_IN', array('REMOVED'));
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DISABLED'));

// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Ad Performance Report #' . uniqid();
$reportDefinition->dateRangeType = 'TODAY';
$reportDefinition->reportType = 'AD_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';

// Set additional options.
$options = array('version' => ADWORDS_VERSION_SPEND);

ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);

您要查找的字段是 'CreativeFinalUrls',只需将其添加到您的选择器字段中,它将 return 最终网址数组 textAd.finalUrls。

$selector->fields = array('AdGroupId', 'CreativeFinalUrls');

https://developers.google.com/adwords/api/docs/appendix/selectorfields?hl=en#v201506