Search in sources :

Example 1 with FeedMappingReturnValue

use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingReturnValue 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());
    }
}
Also used : AttributeFieldMapping(com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping) FeedMappingReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingReturnValue) FeedMappingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface) FeedMapping(com.google.api.ads.adwords.axis.v201809.cm.FeedMapping) FeedMappingOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingOperation)

Aggregations

AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)1 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)1 FeedMappingOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingOperation)1 FeedMappingReturnValue (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingReturnValue)1 FeedMappingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface)1