private static final int PLACEHOLDER_FIELD_LINE_2_TEXT = 4;
private static void createSiteLinksFeedMapping(AdWordsServices adWordsServices,
AdWordsSession session, SiteLinksDataHolder siteLinksData) throws Exception {
// Get the FeedItemService.
FeedMappingServiceInterface feedMappingService =
adWordsServices.get(session, FeedMappingServiceInterface.class);
// 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);
AttributeFieldMapping line1FieldMapping = new AttributeFieldMapping();
line1FieldMapping.setFeedAttributeId(siteLinksData.line1FeedAttributeId);
line1FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_1_TEXT);
AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();
line2FieldMapping.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
line2FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_2_TEXT);
// Create the FieldMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setPlaceholderType(PLACEHOLDER_SITELINKS);
feedMapping.setFeedId(siteLinksData.siteLinksFeedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] {linkTextFieldMapping,
linkUrlFieldMapping, line1FieldMapping, line2FieldMapping});
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());