Here are few issues I noticed with your UpdateSitelinks example (I'll be
referring specifically to PHP version of the example
<https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201406/AdvancedOperations/UpdateSitelinks.php>
):
- 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.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/9c46ef7c-4131-4252-97f7-73ee0a936084%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.