Search in sources :

Example 6 with FeedItem

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

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

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

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

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

the class MigrateToExtensionSettings method getFeedItems.

/**
 * Returns the feed items for a feed.
 */
private static List<FeedItem> getFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed) throws RemoteException {
    // Get the FeedItemService.
    FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
    String query = String.format("SELECT FeedItemId, AttributeValues WHERE Status = 'ENABLED' AND FeedId = %d", feed.getId());
    List<FeedItem> feedItems = new ArrayList<>();
    int offset = 0;
    FeedItemPage feedItemPage;
    do {
        String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
        feedItemPage = feedItemService.query(pageQuery);
        if (feedItemPage.getEntries() != null) {
            feedItems.addAll(Arrays.asList(feedItemPage.getEntries()));
        }
        offset += PAGE_SIZE;
    } while (offset < feedItemPage.getTotalNumEntries());
    return feedItems;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) ExtensionFeedItem(com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem) SitelinkFeedItem(com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem) FeedItemServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface) ArrayList(java.util.ArrayList) FeedItemPage(com.google.api.ads.adwords.axis.v201809.cm.FeedItemPage)

Aggregations

FeedItem (com.google.api.ads.adwords.axis.v201809.cm.FeedItem)9 FeedItemOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)7 FeedItemServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface)5 FeedItemAttributeValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue)4 ArrayList (java.util.ArrayList)4 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)3 FeedItemReturnValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemReturnValue)3 SitelinkFeedItem (com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem)3 FeedItemTargetOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetOperation)2 FeedItemTargetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetServiceInterface)2 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)1 CustomerFeed (com.google.api.ads.adwords.axis.v201809.cm.CustomerFeed)1 CustomerFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CustomerFeedOperation)1 CustomerFeedReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CustomerFeedReturnValue)1 CustomerFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CustomerFeedServiceInterface)1 Feed (com.google.api.ads.adwords.axis.v201809.cm.Feed)1 FeedItemAdGroupTarget (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAdGroupTarget)1 FeedItemCriterionTarget (com.google.api.ads.adwords.axis.v201809.cm.FeedItemCriterionTarget)1 FeedItemGeoRestriction (com.google.api.ads.adwords.axis.v201809.cm.FeedItemGeoRestriction)1