Kazuhiro Kamata
Kazuhiro Kamata

Reputation: 21

Can't get destination URL of Ad by Adwords API

I want to get the destination URL by using Google Adwords API(v201509). Cording with PHP.

In the following code, I'm trying to get the url by using 'get' method of AdGroupAdService. As a result, I could get ad->displayUrl properly but couldn't get ad->url and ad->finalUrls (null given).

What am I doing wrong?

adwords.php with the following code -

$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('Headline', 'Id');
$selector->ordering[] = new OrderBy('Headline', 'ASCENDING');

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

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

    // Display results.
    if (isset($page->entries)) {
        foreach ($page->entries as $adGroupAd) {
            array_push($googleAccountStructure, $adGroupAd);
            //var_dump($adGroupAd);
        }
    }

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

Upvotes: 2

Views: 1036

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 430

Please update your selector fields with this one

$selector->fields = array('Headline', 'Id', 'CreativeFinalUrls', 'Url');

As per adwords api doc if you use Upgraded URLs you need to pass Final URLs in selector fields

https://developers.google.com/adwords/api/docs/reference/v201509/AdGroupAdService.Ad#finalUrls

Upvotes: 4

Related Questions