Search in sources :

Example 1 with FeedMappingOperation

use of com.google.api.ads.adwords.axis.v201809.cm.FeedMappingOperation 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)

Example 2 with FeedMappingOperation

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