CustomTargetingServiceInterface customTargetingService =
user.getService(DfpService.V201311.CUSTOM_TARGETING_SERVICE);
// Sets defaults for page and filter.
CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();
Statement keyFilterStatement = new Statement();
int keyOffset = 0;
do {
// Create a statement to get all custom targeting keys.
keyFilterStatement.setQuery("LIMIT 500 OFFSET " + keyOffset);
// Get custom targeting keys by statement.
keyPage = customTargetingService.getCustomTargetingKeysByStatement(keyFilterStatement);
if (keyPage.getResults() != null) {
int i = keyPage.getStartIndex();
for (CustomTargetingKey key : keyPage.getResults()) {
System.out.println(i + ") Custom targeting key with ID \"" + key.getId()
+ "\", name \"" + key.getName() + "\", display name \"" + key.getDisplayName()
+ "\", and type \"" + key.getType() + "\" was found.");
// Sets defaults for page and filter.
CustomTargetingValuePage valuePage = new CustomTargetingValuePage();
Statement valueFilterStatement = new Statement();
int valueOffset = 0;
do {
// Create a statement to get all custom targeting values for a
// custom targeting key (required) by its ID.
valueFilterStatement.setQuery("WHERE customTargetingKeyId = " + key.getId()
+ " LIMIT 500 OFFSET " + valueOffset);
// Get custom targeting values by statement.
valuePage =
customTargetingService.getCustomTargetingValuesByStatement(valueFilterStatement);