*/
public class GetAllCustomTargetingKeysAndValues {
public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
dfpServices.get(session, CustomTargetingServiceInterface.class);
// Get all custom targeting keys.
List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(dfpServices, session);
// Create a statement to get all custom targeting values for a custom
// targeting key.
StatementBuilder statementBuilder = new StatementBuilder()
.where("customTargetingKeyId = :customTargetingKeyId")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
int totalResultsCounter = 0;
for (Long customTargetingKeyId : customTargetingKeyIds) {
// Set the custom targeting key ID to select from.
statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);
// Default for total result set size and offset.
int totalResultSetSize = 0;
statementBuilder.offset(0);
do {
// Get custom targeting values by statement.
CustomTargetingValuePage page =
customTargetingService.getCustomTargetingValuesByStatement(
statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
for (CustomTargetingValue customTargetingValue : page.getResults()) {