textAd.setDescription2("Low-gravity fun for everyone!");
textAd.setDisplayUrl("www.example.com");
textAd.setUrl("http://www.example.com");
// Create ad group ad.
AdGroupAd textAdGroupAd = new AdGroupAd();
textAdGroupAd.setAdGroupId(adGroupId);
textAdGroupAd.setAd(textAd);
// Create image ad.
ImageAd imageAd = new ImageAd();
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[] {
new TemplateElement("adData", new TemplateElementField[] {
new TemplateElementField("startImage", TemplateElementFieldType.IMAGE,
null, startImage),
new TemplateElementField("displayUrlColor", TemplateElementFieldType.ENUM,
"#ffffff", null),
new TemplateElementField("video", TemplateElementFieldType.VIDEO, null, video)})
});
// Create ad group ad.
AdGroupAd templateAdGroupAd = new AdGroupAd();
templateAdGroupAd.setAdGroupId(adGroupId);
templateAdGroupAd.setAd(templateAd);
// Create operations.
AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
textAdGroupAdOperation.setOperand(textAdGroupAd);
textAdGroupAdOperation.setOperator(Operator.ADD);