// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the CreativeService.
CreativeServiceInterface creativeService =
user.getService(DfpService.V201308.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 an array to store local image creative objects.
Creative[] imageCreatives = new ImageCreative[5];
for (int i = 0; i < 5; i++) {
// Create creative size.
Size size = new Size();
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) {