Search in sources :

Example 81 with Operation

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

the class AddCampaignGroupsAndPerformanceTargets method addCampaignsToGroup.

/**
 * Adds multiple campaigns to a campaign group.
 */
private static void addCampaignsToGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup, List<Long> campaignIds) throws ApiException, RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    List<CampaignOperation> operations = new ArrayList<>();
    for (Long campaignId : campaignIds) {
        Campaign campaign = new Campaign();
        campaign.setId(campaignId);
        campaign.setCampaignGroupId(campaignGroup.getId());
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.SET);
        operations.add(operation);
    }
    CampaignReturnValue returnValue = campaignService.mutate(operations.toArray(new CampaignOperation[operations.size()]));
    System.out.printf("The following campaign IDs were added to the campaign group with ID %d:%n", campaignGroup.getId());
    for (Campaign campaign : returnValue.getValue()) {
        System.out.printf("\t%d%n", campaign.getId());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) ArrayList(java.util.ArrayList)

Example 82 with Operation

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

the class AddCampaignGroupsAndPerformanceTargets method createCampaignGroup.

/**
 * Creates a campaign group.
 */
private static CampaignGroup createCampaignGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignGroupService.
    CampaignGroupServiceInterface campaignGroupService = adWordsServices.get(session, CampaignGroupServiceInterface.class);
    // Create the campaign group.
    CampaignGroup campaignGroup = new CampaignGroup();
    campaignGroup.setName("Mars campaign group #" + System.currentTimeMillis());
    // Create the operation.
    CampaignGroupOperation operation = new CampaignGroupOperation();
    operation.setOperand(campaignGroup);
    operation.setOperator(Operator.ADD);
    CampaignGroup newCampaignGroup = campaignGroupService.mutate(new CampaignGroupOperation[] { operation }).getValue(0);
    System.out.printf("Campaign group with ID %d and name '%s' was created.%n", newCampaignGroup.getId(), newCampaignGroup.getName());
    return newCampaignGroup;
}
Also used : CampaignGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupOperation) CampaignGroup(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroup) CampaignGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupServiceInterface)

Example 83 with Operation

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

Example 84 with Operation

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

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

the class PauseAd method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group for the ad.
 * @param adId the ID of the ad to pause.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, Long adId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create ad with updated status.
    Ad ad = new Ad();
    ad.setId(adId);
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(ad);
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create operations.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperand(adGroupAd);
    operation.setOperator(Operator.SET);
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] { operation };
    // Update ad.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
    // Display ads.
    for (AdGroupAd adGroupAdResult : result.getValue()) {
        System.out.printf("Ad with ID %d, type '%s', and status '%s' was updated.%n", adGroupAdResult.getAd().getId(), adGroupAdResult.getAd().getAdType(), adGroupAdResult.getStatus());
    }
}
Also used : Ad(com.google.api.ads.adwords.axis.v201809.cm.Ad) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)

Aggregations

ArrayList (java.util.ArrayList)24 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)18 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)17 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)16 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)14 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)14 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)13 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)13 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)12 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)12 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)11 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)8 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)8 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)8 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)8