Search in sources :

Example 1 with CampaignFeedServiceInterface

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

the class MigrateToExtensionSettings method getCampaignFeeds.

/**
 * Returns the campaign feeds that use a particular feed for a particular placeholder type.
 */
private static List<CampaignFeed> getCampaignFeeds(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed, int placeholderType) throws RemoteException {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
    String query = String.format("SELECT CampaignId, MatchingFunction, PlaceholderTypes WHERE Status = 'ENABLED' " + "AND FeedId = %d AND PlaceholderTypes CONTAINS_ANY [%d]", feed.getId(), placeholderType);
    List<CampaignFeed> campaignFeeds = new ArrayList<>();
    int offset = 0;
    CampaignFeedPage campaignFeedPage;
    do {
        String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
        campaignFeedPage = campaignFeedService.query(pageQuery);
        if (campaignFeedPage.getEntries() != null) {
            campaignFeeds.addAll(Arrays.asList(campaignFeedPage.getEntries()));
        }
        offset += PAGE_SIZE;
    } while (offset < campaignFeedPage.getTotalNumEntries());
    return campaignFeeds;
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) CampaignFeedPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage) ArrayList(java.util.ArrayList)

Example 2 with CampaignFeedServiceInterface

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

the class AddSiteLinksUsingFeeds method createSiteLinksCampaignFeed.

private static void createSiteLinksCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, Long campaignId) throws RemoteException {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
    // Construct a matching function that associates the sitelink feed items to the campaign, and
    // sets the device preference to mobile. See the matching function guide at
    // https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
    // for more details.
    String matchingFunctionString = String.format("AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, 'Mobile') )", Joiner.on(',').join(siteLinksData.siteLinkFeedItemIds));
    CampaignFeed campaignFeed = new CampaignFeed();
    campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
    campaignFeed.setCampaignId(campaignId);
    Function matchingFunction = new Function();
    matchingFunction.setFunctionString(matchingFunctionString);
    campaignFeed.setMatchingFunction(matchingFunction);
    // Specifying placeholder types on the CampaignFeed allows the same feed
    // to be used for different placeholders in different Campaigns.
    campaignFeed.setPlaceholderTypes(new int[] { PLACEHOLDER_SITELINKS });
    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result = campaignFeedService.mutate(new CampaignFeedOperation[] { operation });
    for (CampaignFeed savedCampaignFeed : result.getValue()) {
        System.out.printf("Campaign with ID %d was associated with feed with ID %d.%n", savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
    }
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) CampaignFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)

Example 3 with CampaignFeedServiceInterface

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

the class MigrateToExtensionSettings method deleteCampaignFeed.

/**
 * Deletes a campaign feed.
 */
private static CampaignFeed deleteCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignFeed campaignFeed) throws RemoteException {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.REMOVE);
    return campaignFeedService.mutate(new CampaignFeedOperation[] { operation }).getValue(0);
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)

Aggregations

CampaignFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface)3 CampaignFeed (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed)2 CampaignFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)2 CampaignFeedPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage)1 CampaignFeedReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue)1 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)1 ArrayList (java.util.ArrayList)1