Search in sources :

Example 36 with Feed

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

the class MigrateToExtensionSettings method deleteOldFeedItems.

/**
 * Deletes the old feed items for which extension settings have been created.
 */
private static void deleteOldFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, Set<Long> feedItemIds, Feed feed) throws RemoteException {
    // Get the FeedItemService.
    FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
    if (feedItemIds.isEmpty()) {
        return;
    }
    List<FeedItemOperation> operations = new ArrayList<>();
    for (Long feedItemId : feedItemIds) {
        FeedItemOperation operation = new FeedItemOperation();
        FeedItem feedItem = new FeedItem();
        feedItem.setFeedId(feed.getId());
        feedItem.setFeedItemId(feedItemId);
        operation.setOperand(feedItem);
        operation.setOperator(Operator.REMOVE);
        operations.add(operation);
    }
    feedItemService.mutate(operations.toArray(new FeedItemOperation[operations.size()]));
}
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) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 37 with Feed

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

the class AddSiteLinksUsingFeeds method restrictFeedItemToGeoTarget.

/**
 * Restricts the first feed item in {@code siteLinksData} to only serve with ads for the specified
 * location ID.
 */
private static void restrictFeedItemToGeoTarget(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, Long locationId) throws RemoteException {
    FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
    // Optional: Restrict the feed item to only serve with ads for the specified geo target.
    FeedItemCriterionTarget feedItemCriterionTarget = new FeedItemCriterionTarget();
    feedItemCriterionTarget.setFeedId(feedItem.getFeedId());
    feedItemCriterionTarget.setFeedItemId(feedItem.getFeedItemId());
    Location location = new Location();
    // The IDs can be found in the documentation or retrieved with the LocationCriterionService.
    location.setId(locationId);
    feedItemCriterionTarget.setCriterion(location);
    FeedItemTargetOperation operation = new FeedItemTargetOperation();
    operation.setOperand(feedItemCriterionTarget);
    operation.setOperator(Operator.ADD);
    feedItemCriterionTarget = (FeedItemCriterionTarget) feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation }).getValue(0);
    System.out.printf("Feed item target for feed ID %d and feed item ID %d was created to restrict serving to " + "location ID %d'.%n", feedItemCriterionTarget.getFeedId(), feedItemCriterionTarget.getFeedItemId(), feedItemCriterionTarget.getCriterion().getId());
}
Also used : FeedItemTargetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetServiceInterface) FeedItemCriterionTarget(com.google.api.ads.adwords.axis.v201809.cm.FeedItemCriterionTarget) FeedItemTargetOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetOperation) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 38 with Feed

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

the class AddSiteLinksUsingFeeds method createSiteLinksFeed.

private static void createSiteLinksFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, String feedName) throws RemoteException {
    // Get the FeedService.
    FeedServiceInterface feedService = adWordsServices.get(session, FeedServiceInterface.class);
    // Create attributes.
    FeedAttribute textAttribute = new FeedAttribute();
    textAttribute.setType(FeedAttributeType.STRING);
    textAttribute.setName("Link Text");
    FeedAttribute finalUrlAttribute = new FeedAttribute();
    finalUrlAttribute.setType(FeedAttributeType.URL_LIST);
    finalUrlAttribute.setName("Link Final URLs");
    FeedAttribute line2Attribute = new FeedAttribute();
    line2Attribute.setType(FeedAttributeType.STRING);
    line2Attribute.setName("Line 2");
    FeedAttribute line3Attribute = new FeedAttribute();
    line3Attribute.setType(FeedAttributeType.STRING);
    line3Attribute.setName("Line 3");
    // Create the feed.
    Feed siteLinksFeed = new Feed();
    siteLinksFeed.setName(feedName);
    siteLinksFeed.setAttributes(new FeedAttribute[] { textAttribute, finalUrlAttribute, line2Attribute, line3Attribute });
    siteLinksFeed.setOrigin(FeedOrigin.USER);
    // Create operation.
    FeedOperation operation = new FeedOperation();
    operation.setOperand(siteLinksFeed);
    operation.setOperator(Operator.ADD);
    // Add the feed.
    FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation });
    Feed savedFeed = result.getValue()[0];
    siteLinksData.siteLinksFeedId = savedFeed.getId();
    FeedAttribute[] savedAttributes = savedFeed.getAttributes();
    siteLinksData.linkTextFeedAttributeId = savedAttributes[0].getId();
    siteLinksData.linkFinalUrlFeedAttributeId = savedAttributes[1].getId();
    siteLinksData.line2FeedAttributeId = savedAttributes[2].getId();
    siteLinksData.line3FeedAttributeId = savedAttributes[3].getId();
    System.out.printf("Feed with name '%s' and ID %d with linkTextAttributeId %d" + " and linkFinalUrlAttributeId %d and line2AttributeId %d" + " and line3AttributeId %d was created.%n", savedFeed.getName(), savedFeed.getId(), savedAttributes[0].getId(), savedAttributes[1].getId(), savedAttributes[2].getId(), savedAttributes[3].getId());
}
Also used : FeedAttribute(com.google.api.ads.adwords.axis.v201809.cm.FeedAttribute) FeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedReturnValue) CampaignFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue) CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) FeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface) FeedOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedOperation) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) Feed(com.google.api.ads.adwords.axis.v201809.cm.Feed)

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