use of com.google.api.ads.adwords.axis.v201809.cm.AgeRange in project googleads-java-lib by googleads.
the class AddDemographicTargetingCriteria method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where demographic targeting will be modified.
* @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) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// https://developers.google.com/adwords/api/docs/appendix/genders
Gender male = new Gender();
male.setId(10L);
BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
genderBiddableAdGroupCriterion.setCriterion(male);
// https://developers.google.com/adwords/api/docs/appendix/ages
AgeRange undetermined = new AgeRange();
undetermined.setId(503999L);
NegativeAdGroupCriterion ageRangeNegativeAdGroupCriterion = new NegativeAdGroupCriterion();
ageRangeNegativeAdGroupCriterion.setAdGroupId(adGroupId);
ageRangeNegativeAdGroupCriterion.setCriterion(undetermined);
AdGroupCriterionOperation genderAdGroupCriterionOperation = new AdGroupCriterionOperation();
genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
genderAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation ageRangeNegativeAdGroupCriterionOperation = new AdGroupCriterionOperation();
ageRangeNegativeAdGroupCriterionOperation.setOperand(ageRangeNegativeAdGroupCriterion);
ageRangeNegativeAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { genderAdGroupCriterionOperation, ageRangeNegativeAdGroupCriterionOperation });
// Display campaigns.
for (AdGroupCriterion adGroupCriterion : result.getValue()) {
System.out.printf("AdGroup criterion with adGroup ID %d, criterion ID %d, " + "and type '%s' was added.%n", adGroupCriterion.getAdGroupId(), adGroupCriterion.getCriterion().getId(), adGroupCriterion.getCriterion().getCriterionType());
}
}
Aggregations