首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >日历同步-安装onEventUpdated触发器

日历同步-安装onEventUpdated触发器
EN

Stack Overflow用户
提问于 2020-09-30 07:02:07
回答 1查看 187关注 0票数 3

Topline:,我有一个我不明白的问题;如果我在脚本编辑器中手动运行这段代码,我可以这样做:

代码语言:javascript
复制
ScriptApp.newTrigger('functionname').forUserCalendar('usercalendar').onEventUpdated().create()

但是,当我从清单安装应用程序并试图从用户的角度运行相同的代码时,我会得到一个错误“异常:对不起,服务器错误。请稍候再试。”行: 15,函数: installTrigger,file: code

上下文:,我正在与一个客户端合作,为Google设置一个会议扩展。

这包括让他们的服务器大致跟上用户的任何日历变化--如果我上午10点有一个会议,但在最后一分钟,我把它更改为上午11点,服务器需要知道!

文档实际上有一个关于这个部分的部分:https://developers.google.com/gsuite/add-ons/calendar/conferencing/sync-calendar-changes。其想法是在事件被更新时,外接程序安装一个运行的触发器。您需要做一些过滤,以确保您只发送相关数据,但这是广泛的机制。我根本无法复制创建日历onEventUpdated触发器的能力!

为了演示这个问题,我已经将代码简化为下面的基本代码。这段代码使一个边栏可以在google日历中使用一个按钮。单击该按钮时,它应在代码中指定的日历上安装onEventUpdated触发器。

Code.gs:

代码语言:javascript
复制
//Attempting to install an onEventUpdated - it appears I can't use 'forUserCalendar' when installing as a user, but can when I manually select 'installTrigger()' function in the code editor?

//Functionality/scopes based on those demonstrated here:
//https://developers.google.com/gsuite/add-ons/calendar/conferencing/sync-calendar-changes
//https://developers.google.com/gsuite/add-ons/calendar/conferencing/conferencing-sample?hl=fr#add-on-manifest

function onHomePageOpen(e) {
    let newButton = CardService.newTextButton().setText('Try install sync').setOnClickAction(CardService.newAction().setFunctionName('installTrigger'))
    let card = CardService.newCardBuilder()
        .setHeader(CardService.newCardHeader()
            .setTitle("<h1>Test install sync</h1>"))
        .addSection(CardService.newCardSection().addWidget(newButton))
        .build()
    return card
}

function installTrigger(e) {
    var triggerBuilder = ScriptApp.newTrigger('syncupdate');
    var triggerBuilder2 = triggerBuilder.forUserCalendar('<<YOUR EMAIL IN HERE>>').onEventUpdated().create()
    console.log('triggerBuilder2', triggerBuilder2)
}

function syncupdate() {
    console.log('triggered on update of an event!');
}

manifest.json

代码语言:javascript
复制
{
  "timeZone": "Pacific/Auckland",
  "dependencies": {},
  "oauthScopes": [
    "https://www.googleapis.com/auth/calendar",
    "https://www.googleapis.com/auth/calendar.readonly",
    "https://www.googleapis.com/auth/calendar.events",
    "https://www.googleapis.com/auth/calendar.events.readonly",
    "https://www.google.com/calendar/feeds",
    "https://www.googleapis.com/auth/script.locale",
    "https://www.googleapis.com/auth/calendar.addons.current.event.read",
    "https://www.googleapis.com/auth/calendar.addons.execute",
    "https://www.googleapis.com/auth/calendar.addons.current.event.write",
    "https://www.googleapis.com/auth/script.scriptapp"
  ],
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Test Install Sync",
      "logoUrl": "https://www.gstatic.com/companion/icon_assets/tasks2_2x.png",
      "layoutProperties": {
        "primaryColor": "#123763",
        "secondaryColor": "#1a73e8"
      },
      "useLocaleFromApp": true
    },
    "calendar": {
      "homepageTrigger": {
        "runFunction": "onHomePageOpen"
      },
      "currentEventAccess": "READ_WRITE"
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-09-30 08:31:01

这似乎是个虫子!

我自己对此进行了测试,似乎无论提供的日历ID是硬编码字符串"user@example.com"、从Session.getActiveUser().getEmail()检索还是使用关键字"primary",这个错误都会持续存在。

我相信你已经意识到了,但对于未来的读者来说,已经有一份关于谷歌问题追踪器的报告,其中详细介绍了同样的行为:

Google似乎确实知道这个问题(在撰写这个答案时,这个问题已经被分配了)。有趣的是,这似乎已经在过去的这里报告,但被标记为2020年-08-03。

如果您还没有,我建议在前面两个链接错误的左上角点击☆,因为这让谷歌知道有更多的人遇到了这个问题,因此更有可能被看到速度更快。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64132447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档