为 Google Apps 脚本 Web 应用程序驱动 API 推送通知 [英] Drive API Push Notifications for a Google Apps Script Web App

查看:17
本文介绍了为 Google Apps 脚本 Web 应用程序驱动 API 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Google Drive API 和使用 Google Apps 脚本设置的网络挂钩设置推送通知.我不知道这是否可能.

I want to set up a Push Notification using the Google Drive API and a web hook set up with Google Apps Script. I cannot figure out if this is possible or not.

我无法弄清楚的部分步骤是 域验证步骤. 我有一个使用 doGet 发布的网络应用程序,如下所示:

The part of the steps that I can't figure out are the domain verification steps. I have a web app published with a doGet as below:

function doGet() {
  refreshCandidates();

  return HtmlService.createHtmlOutput('<b>google site verification</b>')
  .addMetaTag('google-site-verification', 'Iu3xxxxxx')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

当我尝试验证 url 时,它给了我 https://script.google.com/...ZS2/exec 作为端点.但是当我尝试验证它是否点击 https://script.google.com/...ZS2/exec/ 并找到一个完全不同的元标记.

When I try to verify the url it gives me https://script.google.com/...ZS2/exec as an endpoint. But when I try to verify it is hitting https://script.google.com/...ZS2/exec/ and finding a completely different meta tag.

有没有人成功使用过驱动 api 并通过谷歌应用脚​​本推送通知?我错过了什么?

Has anyone successfully used the drive api and push notifications with google apps script? What am I missing?

推荐答案

很遗憾,无法再验证 GAS Web App url.直到 2019 年 8 月左右,还有一个在 Chrome 网上应用店注册"选项.在发布"下可用应用脚本编辑器中的菜单.那时,任何如此注册的 Web 应用程序都会自动验证其 URL.但是,该选项已被删除,搜索控制台下可用的验证方法根本不适用于 GAS Web App url.

Unfortunately, it is no longer possible to verify a GAS Web App url. Up until around August 2019, there was an option to "Register in Chrome Web Store" available under the "Publish" menu in the App Script editor. Back then any Web App so registered would have its URL automatically verified. However, that option has since been removed, and the verification methods available under the search console simply do not work for GAS Web App urls.

此外,即使验证可行,也无法有效利用 Drive Push 通知,因为所有相关通知信息都存储在 HTTP 标头中,这些信息无法通过 GAS doPost() 函数访问.

Furthermore, even when verification was feasible, it was not possible to effectively leverage Drive Push notifications since all relevant notification information is stored in HTTP headers which are not accessible from a GAS doPost() function.

Google Apps 脚本不再是在大多数服务(Gmail、 Drive、Calendar、Admin Directory 等)中实施 Google API 推送通知的可行平台.如果您想坚持使用 Google 的云产品,您可以探索其他替代方案.Google Cloud Functions 就是这样一种选择.

Google Apps Script is no longer a viable platform for implementing Google API Push Notifications across most services (Gmail, Drive, Calendar, Admin Directory etc.). If you want to stick with Google's cloud offerings, there are alternatives you can explore. Google Cloud Functions is one such option.

更新:Gmail 利用 Cloud Pubsub 进行推送通知,该服务最近已更新,无需对推送端点进行域验证.因此,现在可以在这种情况下使用 GAS Web 应用 URL.

UPDATE: Gmail leverages Cloud Pubsub for push notifications and this service has recently been updated to remove the need for domain verification for push endpoints. So, going forward its now possible to use GAS Web App URLs in this scenario.

这篇关于为 Google Apps 脚本 Web 应用程序驱动 API 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆