size.setWidth(300);
size.setHeight(250);
size.setIsAspectRatio(false);
// Create a custom creative.
CustomCreative customCreative = new CustomCreative();
customCreative.setName("Custom creative #" + new Random().nextInt(Integer.MAX_VALUE));
customCreative.setAdvertiserId(advertiserId);
customCreative.setDestinationUrl("http://google.com");
customCreative.setSize(size);
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
customCreativeAsset.setAssetByteArray(Media.getMediaDataFromUrl(
"http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
// Filenames must be unique.
customCreativeAsset.setFileName(
String.format("image%s.jpg", new Random().nextInt(Integer.MAX_VALUE)));
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!");
// Create the creative on the server.
Creative[] creatives =