使用 GAS 发布的网络应用程序作为云端硬盘推送通知的处理程序

Use a GAS published web app as a handler for Drive push notifications

如何将 Drive's Push Notifications API 与 GAS Published 应用程序结合使用?

我在下面设置了以下应用程序,它将通过 GET/POST 接收到的任何内容附加到 this sheet 中进行测试,并且尝试将 WATCH 添加到已发布的 URL 中失败了,我收到错误 "Insufficient Permission"。

即使我无法使用 the documentation 中的授权选项,我也可以使用该应用程序吗?

Link to the script file below

var sslog = SpreadsheetApp.openById('1RIxhdCQlZ52-GJG43m4fdMiCLSCtXjK62YxY4M2aXkc').getSheets()[0];

function doPost(e) {
 sslog.appendRow([e]);
  return 200;
}

function doGet(e) {
 sslog.appendRow([e]);
  return 200;
}

function addWatch(){
  var PayLoad = {
    "id": "4baa4sd80-6ass-1asd4e2-bs5fd-0asd848c9a77", // Your channel ID.
    "type": "web_hook",
    "address": "https://script.google.com/macros/s/AKfycbwBoiIBIJaAJVWJb5Tboc_Wz0RNDxaD_8raKnnLWO_WllO3Lnfe/exec", // Your receiving URL.
    "expiration": ((new Date()).getTime() + 1000*60*5)// (Optional) Your requested channel expiration time.
  }
  var headers = { 'Authorization': 'Bearer ' + ScriptApp.getOAuthToken(), 'Content-Type': 'application/json' };
  var url = 'https://www.googleapis.com/drive/v2/files/15flCrMJ4ItmPZzVzdfmOFuz44iG7xSIqSV066BW7G-Q/watch';

  var mod = UrlFetchApp.fetch(url, { headers:headers, payload:JSON.stringify(PayLoad), method:'POST' });
}

我试过使用 Drive.Changes.watch(resource, optionalArgs) from here,但不知道用什么 resource/args。

警告:我自己没能完成这项工作,这让我很沮丧,直到我最终找到一个报告的问题。果然,这不受支持,并且被视为功能请求。 ("Oh, you wanted an API that works! That wasn't explicit in the specification, so now it's a feature request. We'll get around to it Real Soon Now.")

Drive.changes.watch() 的无用性在 Issue 4254: Allow Apps Script webapps to receive and respond to (Drive) push notifications. In the comments for that issue, it's mentioned that this feature gap was described in a presentation shared on YouTube, and "discussed" on Whosebug in Use Google Script's Web App as Webhook to receive Push Notification directly. (Not much actual info in that Q&A, since it turns out the answerer had never actually tried the Drive notification webhook.) The key comment from the issue report is #6 中有详细说明,其中 Googler "ryanr..." 指出 Google Apps 脚本是不支持作为(直接)通知接收器。

然而...

如果您有自己控制的外部服务器,则可以使用它来接收通知,并通过 Google Apps 脚本进行设置。首先,使用脚本中的开发人员控制台启用驱动器 API 并为推送通知设置项目。这还将引导您完成确认对目标域的控制的步骤。