adWordsServices.get(session, CampaignServiceInterface.class);
int offset = 0;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
.fields("Id", "Name", "Labels")
// Labels filtering is performed by ID. You can use containsAny to select campaigns with
// any of the label IDs, containsAll to select campaigns with all of the label IDs, or
// containsNone to select campaigns with none of the label IDs.
.containsAny("Labels", labelId.toString())
.orderAscBy("Name")
.offset(offset)
.limit(PAGE_SIZE)
.build();
CampaignPage page = null;
do {
// Get all campaigns.
page = campaignService.get(selector);
// Display campaigns.
if (page.getEntries() != null) {
for (Campaign campaign : page.getEntries()) {
String labels = Joiner.on(", ").join(Lists.transform(
Lists.newArrayList(campaign.getLabels()), new Function<Label, String>() {
public String apply(Label label) {
return String.format("%d/%s", label.getId(), label.getName());
}
}));
System.out.printf("Campaign found with name '%s' and ID %d and labels: %s.%n",
campaign.getName(), campaign.getId(), labels);
}
} else {
System.out.println("No campaigns were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
} while (offset < page.getTotalNumEntries());
}