private static List<Long> getAllCustomTargetingKeyIds(DfpServices dfpServices, DfpSession session)
throws RemoteException {
List<Long> customTargetingKeyIds = Lists.newArrayList();
// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
dfpServices.get(session, CustomTargetingServiceInterface.class);
// Create a statement to get all custom targeting keys.
StatementBuilder statementBuilder = new StatementBuilder()
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom targeting keys by statement.
CustomTargetingKeyPage page =
customTargetingService.getCustomTargetingKeysByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomTargetingKey customTargetingKey : page.getResults()) {