// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the InventoryService.
InventoryServiceInterface inventoryService =
user.getService(DfpService.V201308.INVENTORY_SERVICE);
// Create a statement to get all ad units.
Statement filterStatement = new Statement("LIMIT 500", null);
// Get ad units by statement.
AdUnitPage page = inventoryService.getAdUnitsByStatement(filterStatement);
if (page.getResults() != null) {
// Update each local ad unit object by enabling AdSense.
for (AdUnit adUnit : page.getResults()) {
adUnit.getInheritedAdSenseSettings().getValue().setAdSenseEnabled(true);
}
// Update the ad units on the server.
AdUnit[] updatedAdUnits = inventoryService.updateAdUnits(page.getResults());
if (updatedAdUnits != null) {
for (AdUnit adUnit : updatedAdUnits) {
System.out.println("Ad unit with ID \"" + adUnit.getId() + "\", name \""
+ adUnit.getName() + "\", and is AdSense enabled \""