Issues with update SiteLinks Feed example

86 views
Skip to first unread message

Tomas Rimkus

unread,
Sep 3, 2014, 7:04:37 AM9/3/14
to adwor...@googlegroups.com
Here are few issues I noticed with your UpdateSitelinks example (I'll be referring specifically to PHP version of the example):
  • There is no need to readd feed attributes which were already added in "AddSitelinks" example.  Adding attributes with the same name multiple times causes ATTRIBUTE_NAMES_NOT_UNIQUE error. AddLine1AndLine2Attributes() function should be removed and UpdateSitelinksExample() function should be changed the following way:
$feedService = $user->GetService('FeedService', ADWORDS_VERSION);
  $feedItemService
= $user->GetService('FeedItemService', ADWORDS_VERSION);

  $selector
= new Selector();
  $selector
->fields = array('Id', 'Attributes');
  $selector
->predicates = array();
  $selector
->predicates[0] = new Predicate('Id', 'EQUALS', array($feedId));

  $response
= $feedService->get($selector);
  $feed
= $response->entries[0];

  $line1Attribute
= $feed->attributes[2];
  $line2Attribute
= $feed->attributes[3];

 
UpdateFeedItems($feedItemService, $feedId, $line1Attribute, $line2Attribute,
      $feedItemDescriptions
);
  • Inside UpdateFeedItems() function there is no need to call $feedItemService->get() when the required feed items can be just created as new objects. The function should modified the following way:
function UpdateFeedItems(AdWordsSoapClient $feedItemService, $feedId,
                             $line1Attribute
, $line2Attribute, $feedItemDescriptions) {
        $feedItemIds
= array_keys($feedItemDescriptions);
        $itemOperations
= array();
       
foreach ($feedItemIds as $feedItemId) {
            $feedItemDescription
= $feedItemDescriptions[$feedItemId];
            $feedItem
= new FeedItem();
            $feedItem
->feedId = $feedId;
            $feedItem
->feedItemId = $feedItemId;

            $itemAttributeValues
= array();
            $itemAttributeValues
[0] = new FeedItemAttributeValue();
            $itemAttributeValues
[0]->feedAttributeId = $line1Attribute->id;
            $itemAttributeValues
[0]->stringValue = $feedItemDescription[0];

            $itemAttributeValues
[1] = new FeedItemAttributeValue();
            $itemAttributeValues
[1]->feedAttributeId = $line2Attribute->id;
            $itemAttributeValues
[1]->stringValue = $feedItemDescription[1];

            $feedItem
->attributeValues = $itemAttributeValues;

            $itemOperations
[] = new FeedItemOperation($feedItem, 'SET');
       
}
        $feedItemService
->mutate($itemOperations);
   
}
  • There is no need for UpdateFeedMappings() at the end of UpdateSitelinksExample() function. The required mappings were already created in AddSitelinks example. Adding same mappings multiple times causes MULTIPLE_MAPPINGS_FOR_PLACEHOLDER_TYPE error.

Josh Radcliff (AdWords API Team)

unread,
Sep 3, 2014, 12:38:35 PM9/3/14
to adwor...@googlegroups.com
Hi,

Thanks for the feedback. We created that example when the LINE 2 and LINE 3 placeholder fields were added to the API and AdWords. At that time, we had users with Feeds for sitelinks that:
  • did not have those attributes, hence the add of FeedItemAttributes to the Feed
  • feed items without those attributes populated, hence the implementation of UpdateFeedItems()
  • a FeedMapping that was missing those attributes, hence the remove and then add of the FeedMapping in UpdateFeedMappings(). Note that the REMOVE/ADD approach is required (instead of a SET) because a FeedMapping is immutable.
If you created your Feed and related objects using the AddSitelinks.php example after November 2013, then you are correct -- there's no need to run UpdateSitelinks. In fact, we may remove UpdateSitelinks in the near future since most people have probably added the LINE 2 and LINE 3 attributes to their feeds by now.

Thanks,
Josh, AdWords API Team

Tomas Rimkus

unread,
Sep 5, 2014, 4:34:27 AM9/5/14
to adwor...@googlegroups.com
You should rename the example to "AddLine1AndLine2AttributesToSitelinks" to avoid confusion because in its current state it's definitely is not "UpdateSitelinks" example.

Josh Radcliff (AdWords API Team)

unread,
Sep 8, 2014, 9:11:26 AM9/8/14
to adwor...@googlegroups.com
Thanks for the feedback. We're reviewing this example and will either rename it as you suggested, modify it for a more common use case (now that the original motivation is no longer needed), or remove it.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages