【问题标题】:Is it possible to insert AppScript triggers to a Google Sheet from PHP是否可以从 PHP 将 AppScript 触发器插入到 Google 表格中
【发布时间】:2021-06-22 09:47:20
【问题描述】:

是否可以通过 PHP 将触发器插入到属于同一域的 Google 表格中。

一些背景知识:我的 wordpress 网站的作者喜欢使用 Google 表格,我想让表格数据与 Firebase 保持同步。我已经弄清楚如何使用 AppScript 通过这个tutorial 触发自动同步到 Firebase。

现在我希望能够在 PHP 中收到来自 writer/admin 的工作表 URL 时,通过将 AppScript 触发器插入工作表来使其成为 sync with firebase

我只是想知道这是否可能,以及从哪里开始......

【问题讨论】:

  • 使用 Apps Script API 您将无法创建触发器。 (如@TheAddonDepot 所述)。也许创建一个带有时间驱动触发器的单个脚本会使用每个工作表的更改来更新 Firebase DB。让我们知道您尝试了什么。

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


【解决方案1】:

我认为 Apps 脚本没有内置的 PHP 触发器,但也许您可以将您的 Apps 脚本部署/构建为 API,然后从您的 PHP 代码中调用该 API?

您可以单独执行函数 (https://developers.google.com/apps-script/api/how-tos/execute),也可以使用 doGet() 和 doPost() 函数将 Apps 脚本作为 GET/POST 调用。

【讨论】:

  • 无法使用 Apps Script API 创建触发器。见limitations
  • 是的,由于 API 无法创建触发器,我无法从 PHP 调用将触发器添加到工作表。我想知道 API 是否可以在工作表中添加插件/自定义菜单,例如切换开关Sync with firebase,当切换打开时,它将启动同步触发器。有可能吗?
【解决方案2】:

使用 Apps 脚本 API - 方法:scripts.run

如果您有可以自行处理的后端语言,则可以在收到新工作表 URL 时运行函数,方法是使用 Method: scripts.run 而不是创建触发器。

参考

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 2016-04-08
    • 2010-12-23
    • 2018-12-02
    • 2017-01-17
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多