Search in sources :

Example 26 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddAdCustomizer method restrictFeedItemToAdGroup.

/**
 * Restricts the feed item to an ad group.
 */
private static void restrictFeedItemToAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, long adGroupId) throws RemoteException {
    // Get the FeedItemTargetingService.
    FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
    FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget();
    adGroupTarget.setFeedId(feedItem.getFeedId());
    adGroupTarget.setFeedItemId(feedItem.getFeedItemId());
    adGroupTarget.setAdGroupId(adGroupId);
    FeedItemTargetOperation operation = new FeedItemTargetOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupTarget);
    FeedItemTargetReturnValue returnValue = feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation });
    FeedItemAdGroupTarget addedAdGroupTarget = (FeedItemAdGroupTarget) returnValue.getValue(0);
    System.out.printf("Feed item target for feed ID %d and feed item ID %d " + "was created to restrict serving to ad group ID %d.%n", addedAdGroupTarget.getFeedId(), addedAdGroupTarget.getFeedItemId(), addedAdGroupTarget.getAdGroupId());
}
Also used : FeedItemTargetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetServiceInterface) FeedItemAdGroupTarget(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAdGroupTarget) FeedItemTargetReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetReturnValue) FeedItemTargetOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetOperation)

Example 27 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddAdCustomizer method createFeedItemAddOperation.

/**
 * Creates a FeedItemOperation that will create a FeedItem with the specified values and ad group
 * target when sent to FeedItemService.mutate.
 *
 * @param name the value for the name attribute of the FeedItem
 * @param price the value for the price attribute of the FeedItem
 * @param date the value for the date attribute of the FeedItem
 * @param adCustomizerFeed the customizer feed
 * @return a new FeedItemOperation for adding a FeedItem
 */
private static FeedItemOperation createFeedItemAddOperation(String name, String price, String date, AdCustomizerFeed adCustomizerFeed) {
    FeedItem feedItem = new FeedItem();
    feedItem.setFeedId(adCustomizerFeed.getFeedId());
    List<FeedItemAttributeValue> attributeValues = new ArrayList<>();
    // FeedAttributes appear in the same order as they were created - Name, Price, Date.
    // See the createCustomizerFeed method for details.
    FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue();
    nameAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(0).getId());
    nameAttributeValue.setStringValue(name);
    attributeValues.add(nameAttributeValue);
    FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue();
    priceAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(1).getId());
    priceAttributeValue.setStringValue(price);
    attributeValues.add(priceAttributeValue);
    FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue();
    dateAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(2).getId());
    dateAttributeValue.setStringValue(date);
    attributeValues.add(dateAttributeValue);
    feedItem.setAttributeValues(attributeValues.toArray(new FeedItemAttributeValue[attributeValues.size()]));
    FeedItemOperation feedItemOperation = new FeedItemOperation();
    feedItemOperation.setOperand(feedItem);
    feedItemOperation.setOperator(Operator.ADD);
    return feedItemOperation;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedItemAttributeValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue) ArrayList(java.util.ArrayList) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 28 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddDynamicPageFeed method createDsaUrlAddOperation.

/**
 * Creates a {@link FeedItemOperation} to add the DSA URL.
 */
private static FeedItemOperation createDsaUrlAddOperation(DSAFeedDetails feedDetails, String url, String labelName) {
    // Create the FeedItemAttributeValues for the URL and label.
    FeedItemAttributeValue urlAttributeValue = new FeedItemAttributeValue();
    urlAttributeValue.setFeedAttributeId(feedDetails.urlAttributeId);
    // See https://support.google.com/adwords/answer/7166527 for page feed URL recommendations and
    // rules.
    urlAttributeValue.setStringValues(new String[] { url });
    FeedItemAttributeValue labelAttributeValue = new FeedItemAttributeValue();
    labelAttributeValue.setFeedAttributeId(feedDetails.labelAttributeId);
    labelAttributeValue.setStringValues(new String[] { labelName });
    // Create the feed item and operation.
    FeedItem feedItem = new FeedItem();
    feedItem.setFeedId(feedDetails.feedId);
    feedItem.setAttributeValues(new FeedItemAttributeValue[] { urlAttributeValue, labelAttributeValue });
    FeedItemOperation operation = new FeedItemOperation();
    operation.setOperand(feedItem);
    operation.setOperator(Operator.ADD);
    return operation;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedItemAttributeValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 29 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddDynamicPageFeed method createFeedItems.

/**
 * Creates the page URLs in the DSA page feed.
 */
private static void createFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, DSAFeedDetails feedDetails, String labelName) throws RemoteException {
    // Get the FeedItemService.
    FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
    // Create operations to add FeedItems.
    FeedItemOperation[] operations = new FeedItemOperation[] { createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/rental-cars", labelName), createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/hotel-deals", labelName), createDsaUrlAddOperation(feedDetails, "http://www.example.com/discounts/flight-deals", labelName) };
    FeedItemReturnValue result = feedItemService.mutate(operations);
    for (FeedItem item : result.getValue()) {
        System.out.printf("Feed item with feed item ID %d was added.%n", item.getFeedItemId());
    }
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedItemServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface) FeedItemReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemReturnValue) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 30 with Feed

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

ArrayList (java.util.ArrayList)11 FeedItem (com.google.api.ads.adwords.axis.v201809.cm.FeedItem)9 FeedItemOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)7 CampaignFeed (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed)6 CampaignFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface)6 Feed (com.google.api.ads.adwords.axis.v201809.cm.Feed)6 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)5 FeedItemAttributeValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue)5 FeedItemServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface)5 SitelinkFeedItem (com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem)5 AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)4 CampaignFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)4 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)4 FeedMappingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface)4 FeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface)4 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 CampaignFeedPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage)3 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)3 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)3 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)3