// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v201309;
import com.google.api.adwords.lib.AdWordsService;
import com.google.api.adwords.lib.AdWordsServiceLogger;
import com.google.api.adwords.lib.AdWordsUser;
import com.google.api.adwords.v201309.cm.AdGroupBidModifier;
import com.google.api.adwords.v201309.cm.AdGroupBidModifierPage;
import com.google.api.adwords.v201309.cm.AdGroupBidModifierServiceInterface;
import com.google.api.adwords.v201309.cm.Paging;
import com.google.api.adwords.v201309.cm.Selector;
/**
* This example illustrates how to retrieve the first 10 ad group level bid modifiers.
*
* Tags: AdGroupBidModifierService.get
*
* @author thagikura@google.com (Takeshi Hagikura)
*/
public class GetAdGroupBidModifier {
private static final int PAGE_SIZE = 10;
public static void main(String[] args) throws Exception {
AdWordsServiceLogger.log();
// Get AdWordsUser from "~/adwords.properties".
AdWordsUser user = new AdWordsUser();
runExample(user);
}
public static void runExample(AdWordsUser user) throws Exception {
// Get the AdGroupBidModifierService.
AdGroupBidModifierServiceInterface bidModifierService =
user.getService(AdWordsService.V201309.ADGROUP_BID_MODIFIER_SERVICE);
int offset = 0;
// Create selector.
Selector selector = new Selector();
selector.setFields(new String[] {"CampaignId", "AdGroupId", "BidModifier", "Id"});
selector.setPaging(new Paging(offset, PAGE_SIZE));
AdGroupBidModifierPage page = bidModifierService.get(selector);
if (page.getEntries() != null) {
for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
String bidModifierValue =
bidModifierResult.getBidModifier() != null ? bidModifierResult.getBidModifier()
.toString()
: "unset";
System.out.printf("Campaign ID '%s', AdGroup ID '%s' Criterion ID '%s' "
+ "has ad group level modifier: '%s'\n", bidModifierResult.getCampaignId(),
bidModifierResult.getAdGroupId(), bidModifierResult.getCriterion().getId(),
bidModifierValue);
}
} else {
System.out.println("No ad group level bid modifiers were found.");
}
}
}