创建条件为Type = RESPONSIVE_DISPLAY_AD
的广告迭代器将
目前仅对旧版广告进行迭代。此条件已弃用;拜托
更新现有代码以明确使用 Type = LEGACY_RESPONSIVE_DISPLAY_AD
。如需针对支持多项文字、图片和视频素材资源的广告创建广告迭代器,请使用条件 Type = MULTI_ASSET_RESPONSIVE_DISPLAY_AD
。
以下代码段展示了这两种自适应展示广告之间的一些 API 差异和相似之处。如需了解详情,请参阅自适应展示广告参考文档。
// let legacyRdaIterator = AdsApp.ads().withCondition("Type = RESPONSIVE_DISPLAY_AD").get();
let legacyRdaIterator = AdsApp.ads().withCondition("Type = LEGACY_RESPONSIVE_DISPLAY_AD").get();
while (legacyRdaIterator.hasNext()) {
let responsiveDisplayAd = legacyRdaIterator.next().asType().responsiveDisplayAd();
// Legacy responsive display ads have just one long headline.
let longHeadline = responsiveDisplayAd.getLongHeadline();
// And they have one short headline, too.
let shortHeadline = responsiveDisplayAd.getShortHeadline();
// This call to .getHeadlines() returns null, because the method is not
// meaningful when called on a legacy responsive display ad.
assert(responsiveDisplayAd.getHeadlines() === null);
// ... etc. ...
}
let rdaIterator = AdsApp.ads().withCondition("Type = MULTI_ASSET_RESPONSIVE_DISPLAY_AD").get();
while (rdaIterator.hasNext()) {
let responsiveDisplayAd = rdaIterator.next().asType().responsiveDisplayAd();
// Responsive display ads have just one long headline.
let longHeadline = responsiveDisplayAd.getLongHeadline();
// But they can have multiple short headline text assets.
let shortHeadlineAssets = responsiveDisplayAd.getHeadlines();
// This call to .getShortHeadline() returns null, because the method is only
// meaningful when called on a legacy responsive display ad.
assert(responsiveDisplayAd.getShortHeadline() === null);
// ... etc. ...
}
let rdaAndLegacyIterator = AdsApp.ads().withCondition("Type IN [LEGACY_RESPONSIVE_DISPLAY_AD, MULTI_ASSET_RESPONSIVE_DISPLAY_AD]").get();
while (rdaAndLegacyIterator.hasNext()) {
let responsiveDisplayAd = legacyRdaIterator.next().asType().responsiveDisplayAd();
let longHeadline = responsiveDisplayAd.getLongHeadline();
// The .isLegacy() method can be used to differentiate between responsive
// display ad types within an iterator over both.
if (responsiveDisplayAd.isLegacy()) {
let shortHeadline = responsiveDisplayAd.getShortHeadline();
// ... etc. ...
} else {
let shortHeadlineAssets = responsiveDisplayAd.getHeadlines();
// ... etc. ...
}
}