资源
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在制作效果最大化广告系列之前,请务必导入您计划在广告系列中使用的所有素材资源。您可以随时返回并稍后添加素材资源,但您需要一组素材资源才能开始。
在规划广告系列时,请先了解效果最大化广告系列的素材资源和素材资源要求。
由于文字素材资源和图片素材资源是主要必需的素材资源类型,因此本指南将演示如何上传这两种素材资源。这些原则也适用于其他类型的素材资源。无论您要制作哪种类型的素材资源,都可以使用 AssetOperation
来创建。
可以使用 AdsApp
创建素材资源,而无需使用 mutate,但为了保持一致性,本指南采用的方式与所有其他操作相同。请注意,如果您已有可用的素材资源,可以并且应该重复使用这些素材资源。因此,虽然您必须拥有素材资源才能制作效果最大化广告系列,但可能并不一定需要在制作广告系列的过程中制作这些素材资源。
文字素材资源
文字素材资源的运作方式与其他任何操作一样。如果您要在创建广告系列的过程中上传素材资源,请使用临时 ID。否则,请记下返回的资源名称,以便在以后的操作中引用该素材资源,将其添加到素材资源组。
const textAsset = {
"assetOperation": {
"create": {
"resourceName": `customers/${customerId}/assets/${getNextTempId()}`,
"textAsset": {
"text": "Travel the World"
}
}
}
}
operations.push(textAsset);
图片素材资源
图片素材资源以 base-64 编码格式上传。由于您无法直接将图片上传到 Google Ads 脚本中,因此可以选择两种不同的方法来获取图片数据并对其进行编码以供上传。
如需从 Google 云端硬盘中提取图片,您首先需要获取图片的 ID,这是唯一标识图片的最佳方式。获取 ID 的一种方法是从 Google 云端硬盘界面复制可分享的链接,然后提取 ID。您还可以通过编程方式获取一系列文件,然后选择要上传的文件。此代码演示了如何上传具有已知 ID 的单张图片:
const file = DriveApp.getFileById(fileId);
const imageAsset = {
"assetOperation": {
"create": {
"resourceName": `customers/${customerId}/assets/${getNextTempId()}`,
"name": "Marketing Logo",
"type": "IMAGE",
"imageAsset": {
"data": Utilities.base64Encode(file.getBlob().getBytes())
}
}
}
}
或者,您也可以使用 UrlFetchApp
按网址提取托管在网络服务器上的图片:
const file = UrlFetchApp.fetch(imageUrl);
然后,您可以像处理 Google 云端硬盘文件一样对此文件调用 getBlob
,因此操作构建与 Google 云端硬盘文件的步骤相同。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eBefore creating a Performance Max campaign, ensure you have all necessary assets ready, such as text and images, or import them beforehand.\u003c/p\u003e\n"],["\u003cp\u003eFamiliarize yourself with Performance Max asset requirements and specifications detailed in the provided links.\u003c/p\u003e\n"],["\u003cp\u003eLeverage \u003ccode\u003eAssetOperation\u003c/code\u003e to create new assets or reuse existing ones within your campaign.\u003c/p\u003e\n"],["\u003cp\u003eUtilize Google Drive or web URLs to source images, converting them to base-64 encoding for upload as image assets.\u003c/p\u003e\n"],["\u003cp\u003eText assets can be easily integrated by defining their content during campaign setup or by referencing existing ones.\u003c/p\u003e\n"]]],[],null,["# Assets\n\nBefore creating a Performance Max campaign, it's important to import all of the\nassets you plan to use in the campaign. You can always come back and add assets\nlater, but you need a set of assets to even begin.\n\nRead up on [assets](/google-ads/api/performance-max/assets) and\n[asset requirements](/google-ads/api/performance-max/asset-requirements) for\nPerformance Max campaigns while planning your campaign.\n\nSince text assets and image assets are the primary required asset types, this\nguide will demonstrate how to upload each of these. These principles can be\nextended to other asset types as well. No matter what type of asset you're\nmaking, use [`AssetOperation`](/google-ads/api/reference/rpc/v21/AssetOperation) to create\nit.\n\nAssets can be created using the `AdsApp` without using mutate, but for the sake\nof consistency, this guide does it the same way as all the rest\nof the operations. Note that you can and should reuse existing assets if you\nalready have some available. So while it's required that you have assets to\ncreate a Performance Max campaign, it might not be strictly required that you\n*create* them as part of the campaign creation process.\n\nText assets\n-----------\n\nText assets work just like any other operation. If you're uploading assets as\npart of the campaign creation process, use a temp ID. Otherwise, make a note of\nthe returned resource name to use in a future operation when you need to\nreference the asset to add it to an asset group. \n\n const textAsset = {\n \"assetOperation\": {\n \"create\": {\n \"resourceName\": `customers/${customerId}/assets/${getNextTempId()}`,\n \"textAsset\": {\n \"text\": \"Travel the World\"\n }\n }\n }\n }\n operations.push(textAsset);\n\nImage assets\n------------\n\nImage assets are uploaded in a [base-64 encoded](//en.wikipedia.org/wiki/Base64)\nformat. Since you can't upload images directly into Google Ads scripts, you have a\nchoice of two different approaches for getting the image data and encoding it\nfor the upload.\n\nTo fetch an image from Google Drive, first you'll need its\n[ID](/apps-script/reference/drive/file#getId()), which is the best way to\nuniquely identify the image. One way to get the ID is to copy the shareable\nlink from the Google Drive UI and extract the ID. You can also fetch a series\nof files programmatically and select the ones you want to upload. This code\ndemonstrates how to upload a single image with a known ID: \n\n const file = DriveApp.getFileById(fileId);\n const imageAsset = {\n \"assetOperation\": {\n \"create\": {\n \"resourceName\": `customers/${customerId}/assets/${getNextTempId()}`,\n \"name\": \"Marketing Logo\",\n \"type\": \"IMAGE\",\n \"imageAsset\": {\n \"data\": Utilities.base64Encode(file.getBlob().getBytes())\n }\n }\n }\n }\n\nAlternatively, you can fetch an image hosted on a web server by its\nURL by using `UrlFetchApp`: \n\n const file = UrlFetchApp.fetch(imageUrl);\n\nYou can then call `getBlob` on this file just as you would with a Drive file,\nso the operation construction is identical to the steps for a Google Drive file."]]