use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddProductScope method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the shopping campaign.
* @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 campaignId) throws RemoteException {
// Get the campaign criterion service.
CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
ProductScope productScope = new ProductScope();
// This set of dimensions is for demonstration purposes only. It would be
// extremely unlikely that you want to include so many dimensions in your
// product scope.
ProductBrand productBrand = new ProductBrand();
productBrand.setValue("Nexus");
ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
productCanonicalCondition.setCondition(ProductCanonicalConditionCondition.NEW);
ProductCustomAttribute productCustomAttribute = new ProductCustomAttribute();
productCustomAttribute.setType(ProductDimensionType.CUSTOM_ATTRIBUTE_0);
productCustomAttribute.setValue("my attribute value");
ProductOfferId productOfferId = new ProductOfferId();
productOfferId.setValue("book1");
ProductType productTypeLevel1Media = new ProductType();
productTypeLevel1Media.setType(ProductDimensionType.PRODUCT_TYPE_L1);
productTypeLevel1Media.setValue("Media");
ProductType productTypeLevel2Books = new ProductType();
productTypeLevel2Books.setType(ProductDimensionType.PRODUCT_TYPE_L2);
productTypeLevel2Books.setValue("Books");
// The value for the bidding category is a fixed ID for the 'Luggage & Bags'
// category. You can retrieve IDs for categories from the ConstantDataService.
// See the 'GetProductCategoryTaxonomy' example for more details.
ProductBiddingCategory productBiddingCategory = new ProductBiddingCategory();
productBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
productBiddingCategory.setValue(-5914235892932915235L);
productScope.setDimensions(new ProductDimension[] { productBrand, productCanonicalCondition, productCustomAttribute, productOfferId, productTypeLevel1Media, productTypeLevel2Books, productBiddingCategory });
CampaignCriterion campaignCriterion = new CampaignCriterion();
campaignCriterion.setCampaignId(campaignId);
campaignCriterion.setCriterion(productScope);
// Create operation.
CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
criterionOperation.setOperand(campaignCriterion);
criterionOperation.setOperator(Operator.ADD);
// Make the mutate request.
CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation });
// Display the result.
System.out.printf("Created a ProductScope criterion with ID %d.%n", result.getValue(0).getCriterion().getId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createBudget.
/**
* Creates a non-shared budget for a Smart Shopping campaign. Smart Shopping campaigns support
* only non-shared budgets.
*/
private static Budget createBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
// Create a budget.
Budget budget = new Budget();
budget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
Money budgetAmount = new Money();
// This budget equals 50.00 units of your account's currency, e.g.,
// 50 USD if your currency is USD.
budgetAmount.setMicroAmount(50_000_000L);
budget.setAmount(budgetAmount);
budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
// Non-shared budgets are required for Smart Shopping campaigns.
budget.setIsExplicitlyShared(false);
// Create operation.
BudgetOperation budgetOperation = new BudgetOperation();
budgetOperation.setOperand(budget);
budgetOperation.setOperator(Operator.ADD);
// Add the budget.
Budget newBudget = budgetService.mutate(new BudgetOperation[] { budgetOperation }).getValue(0);
System.out.printf("Budget with name '%s' and ID %d was added.%n", newBudget.getName(), newBudget.getBudgetId());
return newBudget;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingAd.
/**
* Creates a Smart Shopping ad.
*/
private static void createSmartShoppingAd(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException {
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create a Smart Shopping ad (Goal-optimized Shopping ad).
GoalOptimizedShoppingAd smartShoppingAd = new GoalOptimizedShoppingAd();
// Create ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(smartShoppingAd);
// Create operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupAdReturnValue adGroupAdAddResult = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation });
// Display result.
adGroupAd = adGroupAdAddResult.getValue(0);
System.out.printf("Smart Shopping ad with ID %d was added.%n", adGroupAd.getAd().getId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingAdGroup.
/**
* Creates a Smart Shopping ad group by setting the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
*/
private static AdGroup createSmartShoppingAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, long campaignId) throws RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group.
AdGroup adGroup = new AdGroup();
adGroup.setCampaignId(campaignId);
adGroup.setName("Smart Shopping ad group #" + System.currentTimeMillis());
// Set the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
adGroup.setAdGroupType(AdGroupType.SHOPPING_GOAL_OPTIMIZED_ADS);
// Create operation.
AdGroupOperation adGroupOperation = new AdGroupOperation();
adGroupOperation.setOperand(adGroup);
adGroupOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupReturnValue adGroupAddResult = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation });
// Display result.
adGroup = adGroupAddResult.getValue(0);
System.out.printf("Smart Shopping ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
return adGroup;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method updateCampaignDsaSetting.
/**
* Updates the campaign DSA setting to add DSA pagefeeds.
*/
private static void updateCampaignDsaSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId, DSAFeedDetails feedDetails) throws ApiException, RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
Selector selector = new SelectorBuilder().fields(CampaignField.Id, CampaignField.Settings).equalsId(campaignId).build();
CampaignPage campaignPage = campaignService.get(selector);
if (campaignPage.getEntries() == null || campaignPage.getTotalNumEntries() == 0) {
throw new IllegalArgumentException("No campaign found with ID: " + campaignId);
}
Campaign campaign = campaignPage.getEntries(0);
if (campaign.getSettings() == null) {
throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
}
DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting) Arrays.stream(campaign.getSettings()).filter(DynamicSearchAdsSetting.class::isInstance).findFirst().orElse(null);
if (dsaSetting == null) {
throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
}
// Use a page feed to specify precisely which URLs to use with your
// Dynamic Search Ads.
PageFeed pageFeed = new PageFeed();
pageFeed.setFeedIds(new long[] { feedDetails.feedId });
dsaSetting.setPageFeed(pageFeed);
// Optional: Specify whether only the supplied URLs should be used with your
// Dynamic Search Ads.
dsaSetting.setUseSuppliedUrlsOnly(true);
Campaign updatedCampaign = new Campaign();
updatedCampaign.setId(campaignId);
updatedCampaign.setSettings(campaign.getSettings());
CampaignOperation operation = new CampaignOperation();
operation.setOperand(updatedCampaign);
operation.setOperator(Operator.SET);
updatedCampaign = campaignService.mutate(new CampaignOperation[] { operation }).getValue(0);
System.out.printf("DSA page feed for campaign ID %d was updated with feed ID %d.%n", updatedCampaign.getId(), feedDetails.feedId);
}
Aggregations