将GAS发布的网络应用程序用作云端硬盘推送通知的处理程序 [英] Use a GAS published web app as a handler for Drive push notifications

查看:43
本文介绍了将GAS发布的网络应用程序用作云端硬盘推送通知的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将驱动器的推送通知API 与GAS发布的应用程序结合使用?

How can I use the Drive's Push Notifications API in conjunction with the GAS Published app?

我在下面设置了以下应用程序,该应用程序将通过GET/POST接收的所有内容附加到此工作表进行测试,并且尝试将WATCH添加到已发布的U​​RL中失败,但出现错误权限不足".

I've setup the folowing App below that appends anything that receives via GET/POST into this sheet for testing, and a failed attempt of adding the WATCH into the published URL, I get the error "Insufficient Permission".

即使我无法使用文档?

链接到下面的脚本文件

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) ,但不知道该如何使用它作为资源/参数.

I've tried to use the Drive.Changes.watch(resource, optionalArgs) from here, but dunno what to use as resource/args.

推荐答案

注意:我自己无法完成这项工作,直到最终找到所报告的问题之前,这令人沮丧.当然,这不受支持,被认为是一项功能请求.(哦,您想要一个起作用的API!在规范中没有明确说明,因此现在是功能请求.我们很快就会解决.")

Caveat: I haven't been able to get this working myself, which was only frustrating until I finally looked for a reported issue. Sure enough, this isn't supported, and is considered a feature request. ("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()的无用性在 将Google Script的Web应用程序作为Webhook来直接接收推送通知.(该问答中没有多少实际信息,因为事实证明,应答者从未实际尝试过Drive通知网络挂钩.)问题报告中的主要评论是

The uselessness of Drive.changes.watch() is spelled out in 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 StackOverflow 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, where Googler "ryanr..." states that Google Apps Script is not supported as a (direct) notification receiver.

但是...

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

If you have an external server that you control, you can use it to receive notifications, and set that up from Google Apps Script. First, use the Developer's Console from your script to enable the Drive API and to set the project up for push notifications. This will also take you through the steps to confirm control of the target domain.

这篇关于将GAS发布的网络应用程序用作云端硬盘推送通知的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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