}
public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create placements.
Placement placement1 = new Placement();
placement1.setUrl("http://mars.google.com");
Placement placement2 = new Placement();
placement2.setUrl("http://example.com/pluto");
// Create biddable ad group criterion.
BiddableAdGroupCriterion placementBiddableAdGroupCriterion1 = new BiddableAdGroupCriterion();
placementBiddableAdGroupCriterion1.setAdGroupId(adGroupId);
placementBiddableAdGroupCriterion1.setCriterion(placement1);
// You can optionally provide these field(s).
placementBiddableAdGroupCriterion1.setUserStatus(UserStatus.PAUSED);
placementBiddableAdGroupCriterion1.setDestinationUrl("http://example.com/mars");
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpmBid bid = new CpmBid();
bid.setBid(new Money(null, 10000000L));
bid.setCpmBidSource(BidSource.CRITERION);
biddingStrategyConfiguration.setBids(new Bids[] {bid});
placementBiddableAdGroupCriterion1.setBiddingStrategyConfiguration(
biddingStrategyConfiguration);
NegativeAdGroupCriterion placementNegativeAdGroupCriterion2 = new NegativeAdGroupCriterion();
placementNegativeAdGroupCriterion2.setAdGroupId(adGroupId);
placementNegativeAdGroupCriterion2.setCriterion(placement2);
// Create operations.
AdGroupCriterionOperation placementAdGroupCriterionOperation1 = new AdGroupCriterionOperation();
placementAdGroupCriterionOperation1.setOperand(placementBiddableAdGroupCriterion1);
placementAdGroupCriterionOperation1.setOperator(Operator.ADD);
AdGroupCriterionOperation placementAdGroupCriterionOperation2 = new AdGroupCriterionOperation();
placementAdGroupCriterionOperation2.setOperand(placementNegativeAdGroupCriterion2);
placementAdGroupCriterionOperation2.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations =
new AdGroupCriterionOperation[] {placementAdGroupCriterionOperation1,
placementAdGroupCriterionOperation2};
// Add placements.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display results.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
System.out.printf(
"Placement ad group criterion with ad group id \"%d\", criterion id \"%d\" "