高级 API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google Ads 脚本中的高级 API 可让经验丰富的开发者连接到某些公共 Google API,所需设置比使用其 HTTP 接口少。您使用这些 API 的方式与使用脚本的内置服务非常相似,它们还提供相同的便利功能,例如自动补全和自动授权。
高级 API 的可能用途
- Google Analytics 4
- 您可以使用 Google Analytics 4 跟踪网站的来访流量,并据此调整广告系列出价。如果您将 Google Analytics 4 媒体资源与 Google Ads 账号相关联,还可以分析客户在您网站上的活动。这些信息可让您了解 Google Ads 为您的网站带来了多少流量或销售额,并帮助您改进广告和网站。您可以通过 Google Analytics 4 了解如何关联 Google Analytics 账号和 Google Ads 账号。
- Google BigQuery
- 您可以将大量数据加载到 Google Cloud Storage 中,然后使用 Google BigQuery 查询这些数据。例如,您可以加载过去 10 年的公开天气数据,然后在脚本中查询某个地区的平均温度,该脚本会使用此信息来调整出价。另一种用途是,对您账号中过去几年的效果数据进行数据分析。
- YouTube 和 YouTube 分析工具
- 您可以检索和更新视频、播放列表等内容,还可以检索视频的效果数据,以便做出出价决策。
- Google 日历
- 脚本可以为未来的任务创建事件(例如,在 2 周后为广告系列生成效果报告),也可以根据您在日历中创建的条目执行操作(例如,在特定日期启用广告系列)。
- 购物内容
- 您的脚本可以在 Apps 脚本中使用 Google Content API for Shopping。此 API 使 Google Merchant Center 用户能够上传和管理其商品详情,以及管理其 Merchant Center 账号。在脚本中,这对于检查商品详情并将特定商品与特定广告相关联非常有用。
- Google Tasks
- 脚本可以为未来的任务创建提醒列表(例如,在两周后运行广告系列的效果报告),也可以根据您在提醒列表中创建的条目执行操作(例如,在特定日期启用广告系列)。
- Google 幻灯片
- 您的脚本可以将广告系列详细信息或统计信息导出到 Google 幻灯片,以便以易于展示的格式发布此类信息。
启用高级 API
如需查看哪些 Google API 可作为高级 API 使用,请点击顶部编辑器栏中的高级 API 按钮。

此时将出现高级 API 对话框。选中您要启用的 API。

接下来,点击 Google API 控制台链接,在控制台中打开与脚本关联的项目所对应的 API 控制台页面;或者,如果您的项目尚未选中,请从“项目”下拉列表中选择该项目。在搜索栏中输入 API 名称,搜索要在脚本中使用的 API。

在搜索结果中选择相应 API,然后在随后出现的页面上选择启用;如果您看到停用按钮,则表示此 API 已启用。对每个要启用的 API 重复此操作。

如需查看为项目启用的 API 列表,请选择信息中心页面。验证您要用于脚本的所有高级 API 是否都已列出。

现在,关闭“高级 API”对话框,返回到编辑器。新 API 将针对您的脚本启用,并显示在自动补全列表中。

可用的 API
以下 API 可供使用:
您还可以参阅我们的代码段页面,了解有关如何使用这些 API 的一些示例。
最后的注意事项
使用高级 API 时,请注意以下几点。
项目 ID
每个 Google Ads 脚本都关联有一个 Google Cloud 项目 ID(也称为项目编号)。您可以打开 高级 API 对话框,然后从该对话框中打开 Google API 控制台页面,以查找脚本的项目编号。此项目 ID 是在您创建脚本时创建的,并且与创建 Google Ads 脚本的用户相关联。如果创建脚本的用户之后从账号中移除,那么尝试访问该脚本的用户会被提示重新授权该脚本并再次设置高级 API 依赖项。系统还会创建一个新的 Google 开发者项目 ID,您需要按照本文档前面部分中的说明再次设置高级 API。
依赖项
只有在账号中创建脚本的用户才能更改相应脚本的高级 API 依赖项。
权限
在访问 API 时,脚本会使用授权该脚本的用户的权限。确保授权脚本的用户对所使用的所有高级 API 以及脚本所需的数据具有必需的访问权限。如果您使用的是 Google Analytics API,请验证授权脚本的用户是否对所访问的 Google Analytics 账号拥有必要的权限。
条款及条件
每项高级 API 可能都有自己的条款及条件,您应在 Google API 控制台中启用相应 API 时接受这些条款及条件。
配额
大多数高级 API 都有一个与之关联的每日免费配额。如果脚本超出此配额,API 将停止运行,直到您请求更多数据或免费配额得到补充为止。您可以打开 Advanced APIs(高级 API)对话框,然后打开相应脚本的 Google API 控制台,监控该脚本使用的配额。Google API 控制台还提供了一种申请 API 额外配额的方式。
结算
某些高级 API 需要您支付使用费。这些付款通过与脚本关联的 Google Cloud 项目进行管理,而不是通过 Google Ads 进行管理。如需详细了解如何为脚本的 Google Cloud 项目启用结算功能,请参阅我们的文档。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eAdvanced APIs in Google Ads scripts allow experienced developers to connect to public Google APIs like Google Analytics, BigQuery, YouTube, and more with simplified setup.\u003c/p\u003e\n"],["\u003cp\u003eThese APIs offer conveniences such as auto-completion and automatic authorization, similar to built-in scripts services.\u003c/p\u003e\n"],["\u003cp\u003eTo enable Advanced APIs, users need to select them in the script editor, enable them in the Google API Console, and ensure the authorized user has necessary permissions.\u003c/p\u003e\n"],["\u003cp\u003eScripts utilize the authorized user's permissions and are subject to each API's terms, conditions, quotas, and potential billing for usage.\u003c/p\u003e\n"],["\u003cp\u003eEach script has an associated Google Cloud Platform Project ID, tied to the creator, which might require reauthorization and setup if the creator is removed from the account.\u003c/p\u003e\n"]]],[],null,["# Advanced APIs\n\nThe advanced APIs in Google Ads scripts let experienced developers connect\nto certain public Google APIs with less setup than using their HTTP interfaces.\nYou use these APIs much like scripts' built-in services, and they offer the same\nconveniences like auto-completion and automatic authorization.\n\nPossible uses for Advanced APIs\n-------------------------------\n\nGoogle Analytics 4\n: You can use Google Analytics 4 to track the traffic coming to your website and\n adjust your campaign bids accordingly. If you link a Google Analytics 4 property\n to your Google Ads account, you can also analyze customer activity on your\n website. This information can shed light on how much of your website traffic or\n sales comes from Google Ads and help you improve your ads and website. You can\n learn more about linking Analytics and Google Ads accounts through\n [Google Analytics 4](//support.google.com/analytics/answer/10089681).\n\nGoogle BigQuery\n: You can load large quantities of data into Google Cloud Storage, and then\n query that data using Google BigQuery. For example, you can load public weather\n data for the past 10 years and then query for a region's average temperature in\n a script that uses that information in adjusting bids. Another use would be to\n do number crunching over your account's performance data over several years.\n\nYouTube and YouTube Analytics\n: You can retrieve and update your videos, playlists, etc. as well as your\n videos' performance data to make bidding decisions.\n\nGoogle Calendar\n: Your script can create events for future tasks (for example, run a\n performance report for your campaigns 2 weeks from today), or perform actions\n based on an entry you created on your calendar (for example, enable a campaign\n on a specific date).\n\nShopping Content\n: Your script can use the Google Content API for Shopping in Apps Script. This\n API gives Google Merchant Center users the ability to upload and manage their\n product listings and manage their Merchant Center accounts. In scripts, this\n can be useful to check product listings and link specific products to specific\n ads.\n\nGoogle Tasks\n: Your script can create a reminder list for future tasks (for example, run a\n performance report for your campaigns two weeks from today), or perform actions\n based on an entry you created in your reminder list (for example, enable a\n campaign on a specific date).\n\nGoogle Slides\n: Your script can export campaign details or statistics to Google Slides to\n publish such information in a presentable format.\n\nEnable Advanced APIs\n--------------------\n\nTo see which Google APIs are available as advanced APIs, click the **Advanced\nAPIs** button on the top editor bar.\n\nThis brings up the **Advanced APIs** dialog. Check the APIs you want to enable.\n\nNext, click the **Google API Console** link to bring up the **API Console**\npage in the Console, with the project associated with your script; or, if\nyour project is not already selected, select it from the Project drop-down\nlist. Search for the APIs you want to use in your script by entering the API\nname in the search bar.\n\nIn the search results, select the API, and on the following page choose\n**Enable** ; if you see a **Disable** button, then this API is already\nenabled. Repeat this action for each API you want to enable.\n\nTo view the list of enabled APIs for the project, select the **Dashboard**\npage. Verify that all the Advanced APIs you want to use for the script are\nlisted.\n\nNow close the Advanced APIs dialog to return to your editor. The new APIs\nwill be enabled for your script and available in the autocomplete list.\n\nAvailable APIs\n--------------\n\nThe following APIs are available for use:\n\n| API Name | Documentation |\n|-------------------|-----------------------------------------------------------------------------------------------------------------|\n| Google Analytics | [https://developers.google.com/apps-script/advanced/analytics](/apps-script/advanced/analytics) |\n| Google BigQuery | [https://developers.google.com/apps-script/advanced/bigquery](/apps-script/advanced/bigquery) |\n| Google Calendar | [https://developers.google.com/apps-script/advanced/calendar](/apps-script/advanced/calendar) |\n| Google Slides | [https://developers.google.com/apps-script/advanced/slides](/apps-script/advanced/slides) |\n| Google Tasks | [https://developers.google.com/apps-script/advanced/tasks](/apps-script/advanced/tasks) |\n| Shopping Content | [https://developers.google.com/apps-script/advanced/shopping-content](/apps-script/advanced/shopping-content) |\n| YouTube | [https://developers.google.com/apps-script/advanced/youtube](/apps-script/advanced/youtube) |\n| YouTube Analytics | [https://developers.google.com/apps-script/advanced/youtube-analytics](/apps-script/advanced/youtube-analytics) |\n\nYou can also refer to our [code snippets page](/google-ads/scripts/docs/examples)\nfor some examples on how to use these APIs.\n\nFinal considerations\n--------------------\n\nThere are a few things to keep in mind when working with the Advanced APIs.\n\n### Project ID\n\nEach Google Ads script has a Google Cloud\n[Project ID](//support.google.com/cloud/answer/6158853)\n(also known as a project number) associated with it. You can find your script's\nproject number by opening the Google API Console page from the **Advanced APIs**\ndialog. This project ID is created when you create the script, and is tied to\nthe user who created the Google Ads script. If the user who created the script\nis later removed from the account, then a user trying to access the script will\nbe prompted to reauthorize the script and setup Advanced API dependencies again.\nA new Google Developer Project ID will also be created, and you will need to\nsetup the Advanced APIs again, as explained earlier in this document.\n\n### Dependencies\n\nOnly the user who created the script in the account can change the Advanced\nAPIs dependencies for that script.\n\n### Permissions\n\nWhen accessing the APIs, a script uses the permissions of the user who\nauthorized the script. Make sure that the user who authorized the script has the\nrequired access to all Advanced APIs being used as well as the data the script\nneeds. If you are using the Google Analytics API, verify that the user who\nauthorized the script has the necessary permissions for the Analytics account\nbeing accessed.\n\n### Terms and Conditions\n\nEach of the Advanced APIs may have its own Terms and Conditions which you\nshould accept when enabling the API in the Google API Console.\n\n### Quota\n\nMost Advanced APIs have a free daily quota associated with it. Once your script\nexceeds this quota, the API will stop working until you request additional\ndata, or the free quota is replenished. You can\n[monitor](//support.google.com/cloud/answer/6158858) the quota used by your\nscript by opening the Google API Console for the script from the **Advanced\nAPIs** dialog. The Google API Console also provides you a way to request\nadditional quota for the API.\n\n### Billing\n\nSome Advanced APIs require you to pay for usage. These payments are managed\nthrough the Google Cloud project associated with your script, and not through\nGoogle Ads. See our\n[documentation](//support.google.com/cloud/answer/6158867) for more details on\nhow to enable billing for your script's Google Cloud project."]]