// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the CreativeService.
CreativeServiceInterface creativeService =
user.getService(DfpService.V201311.CREATIVE_SERVICE);
// Set the ID of the advertiser (company) that all creatives will be
// assigned to.
Long advertiserId = Long.parseLong("INSERT_ADVERTISER_COMPANY_ID_HERE");
// Create the local custom creative object.
CustomCreative customCreative = new CustomCreative();
customCreative.setName("Custom creative");
customCreative.setAdvertiserId(advertiserId);
customCreative.setDestinationUrl("http://google.com");
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
customCreativeAsset.setAssetByteArray(MediaUtils.getAssetDataFromUrl(
"http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
// Filenames must be unique.
customCreativeAsset.setFileName(String.format("image%s.jpg", System.currentTimeMillis()));
customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] {customCreativeAsset});
// Set the HTML snippet using the custom creative asset macro.
customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
"<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" +
"</a><br>Click above for great deals!");
// Set the creative size.
customCreative.setSize(new Size(300, 250, false));
// Create the custom creative on the server.
customCreative = (CustomCreative) creativeService.createCreative(customCreative);
if (customCreative != null) {
System.out.println("A custom creative with ID \"" + customCreative.getId()
+ "\", name \"" + customCreative.getName()
+ "\", and size {" + customCreative.getSize().getWidth()