imageAd.setName("Cruise to mars image ad #" + System.currentTimeMillis());
imageAd.setDisplayUrl("www.example.com");
imageAd.setUrl("http://example.com");
// Create image.
Image image = new Image();
image.setData(ImageUtils.getImageDataFromUrl("http://goo.gl/HJM3L"));
imageAd.setImage(image);
// Create ad group ad.
AdGroupAd imageAdGroupAd = new AdGroupAd();
imageAdGroupAd.setAdGroupId(adGroupId);
imageAdGroupAd.setAd(imageAd);
// Create template ad, using the Click to Play Video template (id 9).
TemplateAd templateAd = new TemplateAd();
templateAd.setTemplateId(9L);
templateAd.setDimensions(new Dimensions(300, 250));
templateAd.setName("Mars Cruise video ad #" + System.currentTimeMillis());
templateAd.setDisplayUrl("www.example.com");
templateAd.setUrl("http://www.example.com");
// Create template ad data.
Image startImage = new Image();
startImage.setData(ImageUtils.getImageDataFromUrl("http://goo.gl/HJM3L"));
startImage.setType(MediaMediaType.IMAGE);
Video video = new Video();
video.setMediaId(videoMediaId);
video.setType(MediaMediaType.VIDEO);
templateAd.setTemplateElements(new TemplateElement[] {