How to access finalUrls in ExpandedTextAd PHP

24 views
Skip to first unread message

Nikola Jordanovski

unread,
Dec 7, 2017, 5:26:20 PM12/7/17
to AdWords API Forum
Hello,

<pre>Google\AdsApi\AdWords\v201708\cm\ExpandedTextAd Object
(
    [headlinePart1:protected] => Woodstock , Paris
    [headlinePart2:protected] => Best Price Guarantee
    [description:protected] => Petit-déjeuner-Internet / WiFi-Draps - Great @RATING-MIN-50@
    [path1:protected] => Woodstock
    [path2:protected] => Paris
    [id:protected] => 238212177963
    [url:protected] => 
    [displayUrl:protected] => 
    [finalUrls:protected] => Array
        (
        )

    [finalMobileUrls:protected] => 
    [finalAppUrls:protected] => 
    [trackingUrlTemplate:protected] => 
    [urlCustomParameters:protected] => 
    [urlData:protected] => 
    [type:protected] => EXPANDED_TEXT_AD
    [devicePreference:protected] => 
    [AdType:protected] => ExpandedTextAd
    [parameterMap:Google\AdsApi\AdWords\v201708\cm\Ad:private] => Array
        (
            [Ad.Type] => AdType
        )

)
</pre>

How can i access the FInalURls?

Peter Oliquino

unread,
Dec 8, 2017, 1:09:26 AM12/8/17
to AdWords API Forum
Hi Nikola,

Could you confirm if you have included the CreativeFinalUrls field in the Selector when you used the AdGroupAdService.get()? If not yet, I would recommend that you do so, and in the response, you will need to iterate through the results of the CreativeFinalUrls field to retrieve the array of final URLs you have specified for your ad. Let me know if this helps.

Thanks and regards,
Peter
AdWords API Team

Nikola Jordanovski

unread,
Dec 8, 2017, 6:53:29 AM12/8/17
to AdWords API Forum
Hello Peter,
Thanks for the answer , here is my function and YES i have included the CreativeFinalUrls


    function GetTextAds($adGroupId)
    {
        // Get the service, which loads the required classes.
        $adWordsServices = new AdWordsServices();
        $adGroupAdService = $adWordsServices->get($this->ad_session, AdGroupAdService::class);
       
        $list_of_text_ads = [];
        // Create selector.
        $selector = new Selector();
        $selector->setFields( array('HeadlinePart1', 'HeadlinePart2','Id','Status','Description','Url','DisplayUrl','CreativeFinalUrls', 'Path1', 'Path2'));
        $selector->setOrdering([new OrderBy('Headline', 'ASCENDING')]);
        $selector->setPredicates([new Predicate('AdGroupId', 'IN', array($adGroupId)), new Predicate('AdType', 'IN', array('EXPANDED_TEXT_AD'))]);
        // By default disabled ads aren't returned by the selector. To return them
        // include the DISABLED status in a predicate.
//        $selector->predicates[] =
//            new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));

        // Create paging controls.
        $selector->setPaging(new Paging(0, self::PAGE_LIMIT)) ;

        do {
            // Make the get request.
            $page = $adGroupAdService->get($selector);
            // Display results.
            if ($page->getEntries() !== null) {
                $totalNumEntries = $page->getTotalNumEntries();
               
                foreach ($page->getEntries() as $adGroupAd) {
                    array_push($list_of_text_ads, $adGroupAd);
                }
            } else {
                return false;
            }

            // Advance the paging index.
            $selector->getPaging()->setStartIndex(
                $selector->getPaging()->getStartIndex() + self::PAGE_LIMIT);
        } while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
       
        return $list_of_text_ads;
    }

Peter Oliquino

unread,
Dec 11, 2017, 2:12:23 AM12/11/17
to AdWords API Forum
Hi Nikola,

Thank you for sending your code. My apologies as I specialize more in Java rather than PHP. However, it appears that in your code you have not yet iterated through the FinalUrls (selected as CreativeFinalUrls) field in order to access its values. You may need to implement an additional foreach functionality in order to go through the array results of the said field.
Reply all
Reply to author
Forward
0 new messages