use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method createSiteLinksFeedMapping.
private static void createSiteLinksFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData) throws RemoteException {
// 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 linkFinalUrlFieldMapping = new AttributeFieldMapping();
linkFinalUrlFieldMapping.setFeedAttributeId(siteLinksData.linkFinalUrlFeedAttributeId);
linkFinalUrlFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_FINAL_URL);
AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();
line2FieldMapping.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
line2FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_2_TEXT);
AttributeFieldMapping line3FieldMapping = new AttributeFieldMapping();
line3FieldMapping.setFeedAttributeId(siteLinksData.line3FeedAttributeId);
line3FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_3_TEXT);
// Create the FeedMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setPlaceholderType(PLACEHOLDER_SITELINKS);
feedMapping.setFeedId(siteLinksData.siteLinksFeedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] { linkTextFieldMapping, linkFinalUrlFieldMapping, line2FieldMapping, line3FieldMapping });
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());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createFeedMapping.
/**
* Creates the feed mapping for the DSA page feeds.
*/
private static void createFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, DSAFeedDetails feedDetails) throws RemoteException {
// Get the FeedMappingService.
FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
// Map the FeedAttributeIds to the fieldId constants.
AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping();
urlFieldMapping.setFeedAttributeId(feedDetails.urlAttributeId);
urlFieldMapping.setFieldId(DSA_PAGE_URLS_FIELD_ID);
AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping();
labelFieldMapping.setFeedAttributeId(feedDetails.labelAttributeId);
labelFieldMapping.setFieldId(DSA_LABEL_FIELD_ID);
// Create the FeedMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setCriterionType(DSA_PAGE_FEED_CRITERION_TYPE);
feedMapping.setFeedId(feedDetails.feedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] { urlFieldMapping, labelFieldMapping });
FeedMappingOperation operation = new FeedMappingOperation();
operation.setOperand(feedMapping);
operation.setOperator(Operator.ADD);
// Add the field mapping.
FeedMapping newFeedMapping = feedMappingService.mutate(new FeedMappingOperation[] { operation }).getValue(0);
System.out.printf("Feed mapping with ID %d and criterionType %d was saved for feed with ID %d.%n", newFeedMapping.getFeedMappingId(), newFeedMapping.getCriterionType(), newFeedMapping.getFeedId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method getFeedMapping.
/**
* Gets the feed mapping for a feed.
*
* @return a multimap from feed attribute ID to the set of field IDs mapped to the attribute
*/
private static Multimap<Long, Integer> getFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed, long placeholderType) throws RemoteException {
// Get the FeedMappingService.
FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
String query = String.format("SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId = %d and PlaceholderType = %d " + "AND Status = 'ENABLED'", feed.getId(), placeholderType);
Multimap<Long, Integer> attributeMappings = HashMultimap.create();
int offset = 0;
FeedMappingPage feedMappingPage;
do {
String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
feedMappingPage = feedMappingService.query(pageQuery);
if (feedMappingPage.getEntries() != null) {
// than one field if needed.
for (FeedMapping feedMapping : feedMappingPage.getEntries()) {
for (AttributeFieldMapping attributeMapping : feedMapping.getAttributeFieldMappings()) {
attributeMappings.put(attributeMapping.getFeedAttributeId(), attributeMapping.getFieldId());
}
}
}
offset += PAGE_SIZE;
} while (offset < feedMappingPage.getTotalNumEntries());
return attributeMappings;
}
Aggregations