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());
}
}
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;
}
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);
}
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()]));
}
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());
}
}
Aggregations