Correct Usage of the ExtensionFeedItem Class

23 views
Skip to first unread message

Peter A

unread,
Jan 14, 2019, 8:45:40 PM1/14/19
to AdWords API and Google Ads API Forum
Hi there,

I am currently in the process of updating a PHP script I use to manage my AdWords Campaigns from v201802 to v201809.

I have however run in to slight issue due to changes to the FeedItem Class.

I currently have a function that looks as follows, built for v201802:

function getFeedItems(AdWordsServices $adWordsServices, AdWordsSession $session, $adCustomizerFeed) {
    
    $page_limit = 500;
    
    // Get the AdCustomizerFeedService, which loads the required classes.
    $feedItemService = $adWordsServices->get($session, FeedItemService::class);
    
    $feedId = $adCustomizerFeed->getFeedId();
        $feedItems = array();
    
    // Create selector.
$selector = new Selector();
    $selector->setFields(array('FeedItemId','Status','AttributeValues','TargetingAdGroupId'));
    
    // Create predicates.
    $selector->setPredicates(array(
        new Predicate('Status', 'EQUALS', array('ENABLED')),
        new Predicate('FeedId', 'EQUALS', array($feedId))
    ));
    
    // Create paging controls.
$selector->setPaging(new Paging(0, $page_limit));
    
$totalNumEntries = 0;
do {
// Make the get request.
$page = $feedItemService->get($selector);

// Display results.
if ($page->getEntries() !== null) {
                        $totalNumEntries = $page->getTotalNumEntries();
            
foreach ($page->getEntries() as $feedItem) {
                                $adGroupId = (int)$feedItem->getAdGroupTargeting()->getTargetingAdGroupId();
$feedPrice = ($feedItem->getAttributeValues())[0]->getStringValue();
$feedShipping = ($feedItem->getAttributeValues())[1]->getStringValue();
$feedItemId = (int)$feedItem->getFeedItemId();
                
$feedItems[$adGroupId][0] = $feedItemId;
$feedItems[$adGroupId][1] = $feedPrice;
$feedItems[$adGroupId][2] = $feedShipping;
}
} else {
printLog(sprintf("No feed items were found.\n"));
}
        
// Advance the paging index.
        $selector->getPaging()->setStartIndex(
            $selector->getPaging()->getStartIndex() + $page_limit
        );
        
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
return $feedItems;
}

The issue is at the following line:

$adGroupId = (int)$feedItem->getAdGroupTargeting()->getTargetingAdGroupId();

As of v201809, the FeedItem class no longer has a 'getAdGroupTargeting' method. Instead, the method has been moved to the ExtensionFeedItem Class.

I have not been able to find any documentation or sample usage of the ExtensionFeedItem class and am unsure on how to modify the above function so that I am still able to retrieve the AdGroup ID from a FeedItem.

Would anyone be willing to show me or point me in the right direction on how I should modify the above function so that I can still get the AdGroup ID from the FeedItem?

Thank you all in advance.

Luis Xander Talag (AdWords API Team)

unread,
Jan 14, 2019, 10:54:48 PM1/14/19
to AdWords API and Google Ads API Forum
Hi Peter,

You may use the FeedItemTargetService.get() method instead to retrieve the details of your FeedItemAdGroupTarget. This object includes the adGroupId of your target ad group.

Let me know if this is what you are looking for.

Thanks and regards,
Luis
AdWords API Team
Reply all
Reply to author
Forward
Message has been deleted
0 new messages