private static final int PLACEHOLDER_FIELD_SITELINK_URL = 2;
private static void createSiteLinksFeedMapping(
AdWordsUser user, SiteLinksDataHolder siteLinksData) throws Exception {
// Get the FeedItemService.
FeedMappingServiceInterface feedMappingService =
user.getService(AdWordsService.V201306.FEED_MAPPING_SERVICE);
// Map the FeedAttributeIds to the fieldId constants.
AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
linkTextFieldMapping.setFeedAttributeId(siteLinksData.linkTextFeedAttributeId);
linkTextFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_LINK_TEXT);
AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping();
linkUrlFieldMapping.setFeedAttributeId(siteLinksData.linkUrlFeedAttributeId);
linkUrlFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_URL);
// Create the FieldMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setPlaceholderType(PLACEHOLDER_SITELINKS);
feedMapping.setFeedId(siteLinksData.siteLinksFeedId);
feedMapping.setAttributeFieldMappings(
new AttributeFieldMapping[] {linkTextFieldMapping, linkUrlFieldMapping});
FeedMappingOperation operation = new FeedMappingOperation();
operation.setOperand(feedMapping);
operation.setOperator(Operator.ADD);
// Save the field mapping.
FeedMappingReturnValue result =
feedMappingService.mutate(new FeedMappingOperation[] {operation});
for (FeedMapping savedFeedMapping : result.getValue()) {
System.out.printf(
"Feed mapping with id %d and placeholderType %d was saved for feed with id %d.\n",
savedFeedMapping.getFeedMappingId(), savedFeedMapping.getPlaceholderType(),
savedFeedMapping.getFeedId());