简体   繁体   English

PHP Adwords API获取升级后的网址

[英]PHP Adwords API get Upgraded URLs

I'm trying to retrieve the Upgraded URLs via the Adwords API, but all I'm gettings is NULL. 我正在尝试通过Adwords API检索升级后的网址,但我得到的只是NULL。 I'm using the latest version of the client library (v201502) Here's the code I'm using 我正在使用最新版本的客户端库(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);

And it returns this 它返回了这一点

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)

What am I doing wrong? 我究竟做错了什么?

Thanks! 谢谢!

The field you're looking for is 'CreativeFinalUrls', just add this to your selector fields and it'll return an array of final urls in textAd.finalUrls. 您正在寻找的字段是'CreativeFinalUrls',只需将其添加到您的选择器字段中,它将返回textAd.finalUrls中的最终网址数组。

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

see https://developers.google.com/adwords/api/docs/appendix/selectorfields?hl=en#v201506 请参阅https://developers.google.com/adwords/api/docs/appendix/selectorfields?hl=zh-CN#v201506

I've found a work around, I'm now using the ReportDefinitionService to get the AD_PERFORMANCE_REPORT for today. 我找到了一个解决方法,我现在正在使用ReportDefinitionService来获取今天的AD_PERFORMANCE_REPORT。

Final Urls are shown in the csv it returns. 最终网址显示在它返回的csv中。

$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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM