Job Castrop
Job Castrop

Reputation: 21

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. I'm using the latest version of the client library (v201502) Here's the code I'm using

    $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!

Upvotes: 1

Views: 750

Answers (2)

Marc North
Marc North

Reputation: 21

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.

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

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

Upvotes: 2

Job Castrop
Job Castrop

Reputation: 21

I've found a work around, I'm now using the ReportDefinitionService to get the AD_PERFORMANCE_REPORT for today.

Final Urls are shown in the csv it 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);

Upvotes: 1

Related Questions