size.setWidth(300);
size.setHeight(250);
size.setIsAspectRatio(false);
// Create an image creative.
ImageCreative imageCreative = new ImageCreative();
imageCreative.setName("Image creative #" + i);
imageCreative.setAdvertiserId(advertiserId);
imageCreative.setDestinationUrl("http://google.com");
imageCreative.setSize(size);
// Create image asset.
CreativeAsset creativeAsset = new CreativeAsset();
creativeAsset.setFileName("image.jpg");
creativeAsset.setAssetByteArray(MediaUtils.getAssetDataFromUrl(
"http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
creativeAsset.setSize(size);
imageCreative.setPrimaryImageAsset(creativeAsset);
imageCreatives[i] = imageCreative;
}
// Create the image creatives on the server.
imageCreatives = creativeService.createCreatives(imageCreatives);
if (imageCreatives != null) {
for (Creative creative : imageCreatives) {
// Use instanceof to determine what type of creative was returned.
if (creative instanceof ImageCreative) {
ImageCreative imageCreative = (ImageCreative) creative;
System.out.println("An image creative with ID \"" + imageCreative.getId()
+ "\", name \"" + imageCreative.getName()
+ "\", and size {" + imageCreative.getSize().getWidth()
+ ", " + imageCreative.getSize().getHeight() + "} was created and\n"
+ " can be previewed at: " + imageCreative.getPreviewUrl());
} else {
System.out.println("A creative with ID \"" + creative.getId()
+ "\", name \"" + creative.getName()
+ "\", and type \"" + creative.getCreativeType() + "\" was created.");
}