int offset = 0;
boolean morePages = true;
// Create selector.
Selector selector = new Selector();
selector.setFields(new String[] {"Id", "AdGroupId", "Status"});
selector.setOrdering(new OrderBy[] {new OrderBy("Id", SortOrder.ASCENDING)});
selector.setPaging(new Paging(offset, PAGE_SIZE));
// Create predicates.
Predicate adGroupIdPredicate =
new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
// By default disabled ads aren't returned by the selector. To return them
// include the DISABLED status in a predicate.
Predicate statusPredicate =
new Predicate("Status", PredicateOperator.IN,
new String[] {"ENABLED", "PAUSED", "DISABLED"});
Predicate adTypePredicate =
new Predicate("AdType", PredicateOperator.EQUALS, new String[] {"THIRD_PARTY_REDIRECT_AD"});
selector.setPredicates(new Predicate[] {adGroupIdPredicate, statusPredicate, adTypePredicate});
while (morePages) {
// Get all ads.
AdGroupAdPage page = adGroupAdService.get(selector);
// Display ads.
if (page.getEntries() != null && page.getEntries().length > 0) {
for (AdGroupAd adGroupAd : page.getEntries()) {
System.out.println("Ad with id \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
+ adGroupAd.getAd().getAdType() + "\" was found.");
}
} else {
System.out.println("No ads were found.");
}
offset += PAGE_SIZE;
selector.getPaging().setStartIndex(offset);
morePages = offset < page.getTotalNumEntries();
}
}