// Get the ContentService.
ContentServiceInterface contentService =
dfpServices.get(session, ContentServiceInterface.class);
// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
dfpServices.get(session, CustomTargetingServiceInterface.class);
// Get the NetworkService.
NetworkServiceInterface networkService =
dfpServices.get(session, NetworkServiceInterface.class);
// Get content browse custom targeting key ID.
long contentBrowseCustomTargetingKeyId =
networkService.getCurrentNetwork().getContentBrowseCustomTargetingKeyId();
if (contentBrowseCustomTargetingKeyId == 0) {
throw new RuntimeException("Your network does not have content categories enabled.");
}
// Create a statement to select the categories matching the name comedy.
Statement categoryFilterStatement = new StatementBuilder()
.where("customTargetingKeyId = :contentBrowseCustomTargetingKeyId and name = :category")
.limit(1)
.withBindVariableValue(
"contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
.withBindVariableValue("category", "comedy").toStatement();
// Get categories matching the filter statement.
CustomTargetingValuePage customTargetingValuePage =
customTargetingService.getCustomTargetingValuesByStatement(categoryFilterStatement);
// Get the custom targeting value ID for the comedy category.
long categoryCustomTargetingValueId = customTargetingValuePage.getResults()[0].getId();
// Create a statement to select all content.