สื่อโฆษณา
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
โฆษณาบางประเภท เช่น
ImageAd และ
ResponsiveDisplayAd
มีรูปภาพและองค์ประกอบสื่ออื่นๆ คู่มือนี้อธิบายวิธีอัปโหลดและ
ค้นหาสื่อโดยใช้สคริปต์ Google Ads
กำลังอัปโหลดอิมเมจ
คุณอัปโหลดรูปภาพได้โดยใช้คลาส
ImageBuilder
ซึ่งต้องระบุชื่อและข้อมูลรูปภาพ ข้อมูลจะแสดงเป็นออบเจ็กต์การแลกเปลี่ยนข้อมูล
Blob
ที่สร้างขึ้นได้โดยบริการต่างๆ เช่น ไดรฟ์หรือ
การดึงข้อมูล URL
ข้อมูลโค้ดต่อไปนี้แสดงวิธีอัปโหลดรูปภาพจาก URL ภายนอก
let imageUrl = "http://www.example.com/example.png";
let imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();
let mediaOperation = AdsApp.adMedia().newImageBuilder()
.withName("IMAGE_NAME")
.withData(imageBlob)
.build();
หรืออาจโหลด Blob รูปภาพจาก Google ไดรฟ์ก็ได้
let imageFileId = "IMAGE_FILE_ID";
let imageBlob = DriveApp.getFileById(imageFileId).getBlob();
let mediaOperation = AdsApp.adMedia().newImageBuilder()
.withName("IMAGE_NAME")
.withData(imageBlob)
.build();
ไฟล์ครีเอทีฟโฆษณาเป็นไฟล์ ZIP ที่มีชิ้นงาน HTML5 ซึ่งใช้สร้างโฆษณา HTML5 ได้
อัปโหลดชุดสื่อด้วยคลาส
MediaBundleBuilder
ซึ่งใช้ชื่อและข้อมูลไฟล์ เช่นเดียวกับรูปภาพ ข้อมูลจะแสดงเป็นออบเจ็กต์การแลกเปลี่ยนข้อมูล Blob
ข้อมูลโค้ดต่อไปนี้แสดงวิธีอัปโหลดไฟล์ครีเอทีฟโฆษณาจาก URL ภายนอก
let mediaBundleUrl = "http://www.example.com/example.zip";
let mediaBundleBlob = UrlFetchApp.fetch(mediaBundleUrl).getBlob();
let mediaOperation = AdsApp.adMedia().newMediaBundleBuilder()
.withName("bundle name")
.withData(mediaBundleBlob)
.build();
คุณค้นหาสื่อทุกประเภทในสคริปต์ Google Ads ได้โดยใช้
MediaSelector
ใช้เพรดิเคต
withCondition(condition)
เพื่อกรองสื่อตามชื่อ ประเภท หรือฟิลด์อื่นๆ ตัวอย่างเช่น ข้อมูลโค้ดต่อไปนี้จะค้นหารูปภาพทั้งหมดในบัญชี
let mediaIterator = AdsApp.adMedia().media()
.withCondition("Type = IMAGE")
.get();
while (mediaIterator.hasNext()) {
let image = mediaIterator.next();
}
ดูตัวอย่างโค้ดบางส่วนสำหรับการสร้างโฆษณาที่รองรับพร้อมสื่อที่แนบมาได้ในบทความเกี่ยวกับโฆษณา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\u003cp\u003eThis guide explains how to upload and query images and media bundles using Google Ads scripts for enhanced ad creatives.\u003c/p\u003e\n"],["\u003cp\u003eYou can upload images and media bundles from external URLs or Google Drive using the \u003ccode\u003eImageBuilder\u003c/code\u003e and \u003ccode\u003eMediaBundleBuilder\u003c/code\u003e classes.\u003c/p\u003e\n"],["\u003cp\u003eQuery existing media using the \u003ccode\u003eMediaSelector\u003c/code\u003e to filter by criteria such as name or type, enabling you to manage and reuse your assets.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the ads article for practical examples of creating ads with attached media to leverage these functionalities.\u003c/p\u003e\n"]]],[],null,["Some ad types, such as\n[ImageAd](/google-ads/scripts/docs/reference/adsapp/adsapp_imagead) and\n[ResponsiveDisplayAd](/google-ads/scripts/docs/reference/adsapp/adsapp_responsivedisplayad),\ncontain images and other media elements. This guide describes how to upload and\nquery media using Google Ads scripts.\n\nUploading images\n\nImages can be uploaded using the\n[`ImageBuilder`](/google-ads/scripts/docs/reference/adsapp/adsapp_imagebuilder)\nclass, which takes a name and image data. The data is provided as a\n[`Blob`](/apps-script/reference/base/blob) data interchange object that can be\ncreated by services such as [Drive](/apps-script/reference/drive) or\n[URL fetch](/apps-script/reference/url-fetch).\n\nThe following snippet shows how to upload an image from an external URL: \n\n let imageUrl = \"http://www.example.com/example.png\";\n let imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();\n let mediaOperation = AdsApp.adMedia().newImageBuilder()\n .withName(\"IMAGE_NAME\")\n .withData(imageBlob)\n .build();\n\nAlternatively, the image blob may be loaded from Google Drive: \n\n let imageFileId = \"IMAGE_FILE_ID\";\n let imageBlob = DriveApp.getFileById(imageFileId).getBlob();\n let mediaOperation = AdsApp.adMedia().newImageBuilder()\n .withName(\"IMAGE_NAME\")\n .withData(imageBlob)\n .build();\n\nUploading media bundles\n\nMedia bundles are ZIP archives that contain HTML5 assets, which can be used to\ncreate [HTML5 ads](//support.google.com/google-ads/answer/1722096#otherhtml5).\nUpload media bundles with the\n[`MediaBundleBuilder`](/google-ads/scripts/docs/reference/adsapp/adsapp_mediabundlebuilder)\nclass, which takes a name and file data. As with images, data is provided as\na [`Blob`](/apps-script/reference/base/blob) data interchange object.\n\nThe following snippet shows how to upload a media bundle from an external URL: \n\n let mediaBundleUrl = \"http://www.example.com/example.zip\";\n let mediaBundleBlob = UrlFetchApp.fetch(mediaBundleUrl).getBlob();\n let mediaOperation = AdsApp.adMedia().newMediaBundleBuilder()\n .withName(\"bundle name\")\n .withData(mediaBundleBlob)\n .build();\n\nQuerying media\n\nMedia of every type can be queried in Google Ads scripts using a\n[`MediaSelector`](/google-ads/scripts/docs/reference/adsapp/adsapp_mediaselector).\nUse the\n[`withCondition()`](/google-ads/scripts/docs/reference/adsapp/adsapp_mediaselector#withCondition_1)\npredicate to filter media by name, type, or other fields. For example, the\nfollowing snippet finds all images in an account: \n\n let mediaIterator = AdsApp.adMedia().media()\n .withCondition(\"Type = IMAGE\")\n .get();\n while (mediaIterator.hasNext()) {\n let image = mediaIterator.next();\n }\n\nCreating ads with media\n\nSee our [ads article](/google-ads/scripts/docs/examples/ads) for some code\nexamples of creating supported ads with attached media."]]