use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method addWebPageCriteria.
/**
* Adds a web page criteria to target Dynamic Search Ads.
*/
private static void addWebPageCriteria(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create a webpage criterion for special offers.
WebpageParameter param = new WebpageParameter();
param.setCriterionName("Special offers");
WebpageCondition urlCondition = new WebpageCondition();
urlCondition.setOperand(WebpageConditionOperand.URL);
urlCondition.setArgument("/specialoffers");
WebpageCondition titleCondition = new WebpageCondition();
titleCondition.setOperand(WebpageConditionOperand.PAGE_TITLE);
titleCondition.setArgument("Special Offer");
param.setConditions(new WebpageCondition[] { urlCondition, titleCondition });
Webpage webpage = new Webpage();
webpage.setParameter(param);
// Create biddable ad group criterion.
BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
biddableAdGroupCriterion.setAdGroupId(adGroup.getId());
biddableAdGroupCriterion.setCriterion(webpage);
biddableAdGroupCriterion.setUserStatus(UserStatus.PAUSED);
// Optional: set a custom bid.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpcBid bid = new CpcBid();
bid.setBid(new Money());
bid.getBid().setMicroAmount(10000000L);
biddingStrategyConfiguration.setBids(new Bids[] { bid });
biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Create operations.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(biddableAdGroupCriterion);
// Create the criterion.
AdGroupCriterion newAdGroupCriterion = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
System.out.printf("Webpage criterion with ID %d was added to ad group ID %d.%n", newAdGroupCriterion.getCriterion().getId(), newAdGroupCriterion.getAdGroupId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createAdGroup.
/**
* Creates the ad group.
*/
private static AdGroup createAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, Campaign campaign) throws ApiException, RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create the ad group.
AdGroup adGroup = new AdGroup();
// Required: Set the ad group's type to Dynamic Search Ads.
adGroup.setAdGroupType(AdGroupType.SEARCH_DYNAMIC_ADS);
adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
adGroup.setCampaignId(campaign.getId());
adGroup.setStatus(AdGroupStatus.PAUSED);
// Recommended: Set a tracking URL template for your ad group if you want to use URL
// tracking software.
adGroup.setTrackingUrlTemplate("http://tracker.example.com/traveltracker/{escapedlpurl}");
// Set the ad group bids.
BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
CpcBid cpcBid = new CpcBid();
cpcBid.setBid(new Money());
cpcBid.getBid().setMicroAmount(3000000L);
biddingConfig.setBids(new Bids[] { cpcBid });
adGroup.setBiddingStrategyConfiguration(biddingConfig);
// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.ADD);
AdGroup newAdGroup = adGroupService.mutate(new AdGroupOperation[] { operation }).getValue(0);
System.out.printf("Ad group with name '%s' and ID %d was added.%n", newAdGroup.getName(), newAdGroup.getId());
return newAdGroup;
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createExpandedDSA.
/**
* Creates the expanded Dynamic Search Ad.
*/
private static void createExpandedDSA(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create the expanded Dynamic Search Ad. This ad will have its headline and final URL
// auto-generated at serving time according to domain name specific information provided
// by DynamicSearchAdsSetting at the campaign level.
ExpandedDynamicSearchAd expandedDSA = new ExpandedDynamicSearchAd();
// Set the ad description.
expandedDSA.setDescription("Buy your tickets now!");
expandedDSA.setDescription2("Discount ends soon");
// Create the ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroup.getId());
adGroupAd.setAd(expandedDSA);
// Optional: Set the status.
adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupAd);
// Create the ad.
AdGroupAd newAdGroupAd = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }).getValue(0);
ExpandedDynamicSearchAd newExpandedDSA = (ExpandedDynamicSearchAd) newAdGroupAd.getAd();
System.out.printf("Expanded Dynamic Search Ad with ID %d and description '%s' and description 2 '%s' was " + "added.%n", newExpandedDSA.getId(), newExpandedDSA.getDescription(), newExpandedDSA.getDescription2());
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createBudget.
/**
* Creates the budget.
*/
private static Budget createBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException, ApiException {
// Get the BudgetService.
BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
// Create a budget, which can be shared by multiple campaigns.
Budget sharedBudget = new Budget();
sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
Money budgetAmount = new Money();
budgetAmount.setMicroAmount(50000000L);
sharedBudget.setAmount(budgetAmount);
sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
BudgetOperation budgetOperation = new BudgetOperation();
budgetOperation.setOperand(sharedBudget);
budgetOperation.setOperator(Operator.ADD);
// Add the budget
Budget budget = budgetService.mutate(new BudgetOperation[] { budgetOperation }).getValue(0);
return budget;
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddGmailAd method main.
public static void main(String[] args) {
AdWordsSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
// Construct an AdWordsSession.
session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
AddGmailAdParams params = new AddGmailAdParams();
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the command line, or insert them
// into the code here. See the parameter class definition above for descriptions.
params.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
}
try {
runExample(adWordsServices, session, params.adGroupId);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an API request. Instances
// of this exception have a message and a collection of ApiErrors that indicate the
// type and underlying cause of the exception. Every exception object in the adwords.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must appear before the
// catch block for RemoteException.
System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
} catch (IOException ioe) {
System.err.printf("Example failed due to IOException: %s%n", ioe);
}
}
Aggregations