【问题标题】:How do you access the Google Sheets API via a Google Apps Script?您如何通过 Google Apps 脚本访问 Google Sheets API?
【发布时间】:2021-03-24 21:46:06
【问题描述】:

我正在尝试通过 Google Apps 脚本调用 Google Sheets API。例如,我已按照此处提供的说明进行操作:

https://developers.google.com/sheets/api/quickstart/js

我已按照其他地方的建议通过我的 Google Cloud Platform 项目生成了客户端 ID 和 API 密钥。

现在,我创建了一个包含两个文件的 google 应用程序脚本,即 Code.gs 文件和一个名为 index.html 的文件,其中包含从上面的 Google Sheets API 快速入门复制和粘贴的代码(插入了我的客户端 ID 和 API) .

在测试部署时,我收到以下错误消息:

{
  "error": "idpiframe_initialization_failed",
  "details": "Not a valid origin for the client: https://<some numbers>-script.googleusercontent.com has not been registered for client ID <MY_CLIENT_ID>. Please go to https://console.developers.google.com/ and register this origin for your project's client ID."
}

我已将 script.google.com 注册为我的项目的来源。

我做错了什么吗?我将如何从这里开始克服这个错误?

【问题讨论】:

  • 欢迎来到Stack Overflow。您知道 Google Sheets API 已经集成到 Google Apps Script 中了吗?请参阅 Apps 脚本文档中的高级服务部分。
  • 与 Google Apps 脚本中的高级服务相关 -> stackoverflow.com/q/65832570/1595451
  • @Rubén 我不知道这一点。谢谢!很有帮助。

标签: google-apps-script google-sheets-api


【解决方案1】:

如果您想在 Apps 脚本中使用 Sheets API,则必须使用表格高级服务。

为此,您必须转到Services +,然后添加Google Sheets API

由于这是一项高级服务,授权流程将由 Google 处理,因此您无需提供 clientIdAPI key

参考

【讨论】:

    猜你喜欢
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多