function main() {
// If you have multiple adGroups or images with the same name, this
// snippet will pick an arbitrary match each time. In such cases, just
// filter on the campaign name or media ID as well:
//
// AdsApp.adGroups()
// .withCondition('Name = "Test Group for Responsive Display Ads"')
// .withCondition('CampaignName = "Example Campaign Name"')
var adGroupIterator = AdsApp.adGroups()
.withCondition('Name = "Test Group for Responsive Display Ads"')
.withCondition('CampaignName = "Example Campaign Name"')
.get();
// Upload a marketing image
var imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();
var mediaOperation = AdsApp.adMedia().newImageBuilder()
.withName("marketingImage1")
.withData(imageBlob)
.build();
var marketingImage = mediaOperation.getResult();
marketingImage
// Upload a square marketing image
var imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();
var mediaOperation = AdsApp.adMedia().newImageBuilder()
.withName("squareMarketingImage1")
.withData(imageBlob)
.build();
var squareMarketingImage = mediaOperation.getResult();
squareMarketingImage
var mediaIterator = AdsApp.adMedia().media()
.withCondition('Name CONTAINS "Image1"')
.get();
if (adGroupIterator.hasNext() && mediaIterator.hasNext()) {
var adGroup = adGroupIterator.next();
var marketingImage = mediaIterator.next();
adGroup.newAd().responsiveDisplayAdBuilder()
.withShortHeadline('Short headline')
.withLongHeadline('Long headline')
.withDescription('Description')
.withBusinessName('Business name')
.withMarketingImage(marketingImage)
.withMarketingImage(squareMarketingImage)
.build();
// ResponsiveDisplayAdBuilder has additional options.
// For more details, see
}
}...