if (page.getResults() != null) {
Creative[] creatives = page.getResults();
long[] oldIds = new long[creatives.length];
for (int i = 0; i < creatives.length; i++) {
ImageCreative imageCreative = (ImageCreative) creatives[i];
oldIds[i] = imageCreative.getId();
imageCreative.setId(null);
imageCreative.setAdvertiserId(imageCreative.getAdvertiserId());
imageCreative.setName(
imageCreative.getName() + " (Copy #" + System.currentTimeMillis() + ")");
// Create image asset.
CreativeAsset creativeAsset = new CreativeAsset();
creativeAsset.setFileName("image.jpg");
creativeAsset.setAssetByteArray(
MediaUtils.getAssetDataFromUrl(imageCreative.getPrimaryImageAsset().getAssetUrl()));
creativeAsset.setSize(imageCreative.getPrimaryImageAsset().getSize());
imageCreative.setPrimaryImageAsset(creativeAsset);
creatives[i] = imageCreative;
}
// Create the copied creative.