private static void createSiteLinksFeedMapping( AdWordsUser user, SiteLinksDataHolder siteLinksData) { // Get the FeedItemService. FeedMappingService feedMappingService = (FeedMappingService) user.GetService(AdWordsService.v201306.FeedMappingService); // Map the FeedAttributeIds to the fieldId constants. AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping(); linkTextFieldMapping.feedAttributeId = siteLinksData.LinkTextFeedAttributeId; linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT; AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping(); linkUrlFieldMapping.feedAttributeId = siteLinksData.LinkUrlFeedAttributeId; linkUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_URL; // Create the FieldMapping and operation. FeedMapping feedMapping = new FeedMapping(); feedMapping.placeholderType = PLACEHOLDER_SITELINKS; feedMapping.feedId = siteLinksData.SiteLinksFeedId; feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {linkTextFieldMapping, linkUrlFieldMapping}; FeedMappingOperation operation = new FeedMappingOperation(); operation.operand = feedMapping; operation.@operator = Operator.ADD; // Save the field mapping. FeedMappingReturnValue result = feedMappingService.mutate(new FeedMappingOperation[] {operation}); foreach (FeedMapping savedFeedMapping in result.value) { Console.WriteLine( "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.", savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType, savedFeedMapping.feedId); } }
/// <summary> /// Map the feed for use with Sitelinks. /// </summary> /// <param name="feedMappingService">The feed mapping service.</param> /// <param name="siteLinksFeed">The feed for holding sitelinks.</param> private static void createSiteLinksFeedMapping(FeedMappingService feedMappingService, SiteLinksFeed siteLinksFeed) { // Map the FeedAttributeIds to the fieldId constants. AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping(); linkTextFieldMapping.feedAttributeId = siteLinksFeed.LinkTextFeedAttributeId; linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT; AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping(); linkUrlFieldMapping.feedAttributeId = siteLinksFeed.LinkUrlFeedAttributeId; linkUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_URL; // Create the FieldMapping and operation. FeedMapping feedMapping = new FeedMapping(); feedMapping.placeholderType = PLACEHOLDER_SITELINKS; feedMapping.feedId = siteLinksFeed.SiteLinksFeedId; feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {linkTextFieldMapping, linkUrlFieldMapping}; FeedMappingOperation operation = new FeedMappingOperation(); operation.operand = feedMapping; operation.@operator = Operator.ADD; // Save the field mapping. feedMappingService.mutate(new FeedMappingOperation[] {operation}); }