首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试更新事件时出现“无效参数数”错误

尝试更新事件时出现“无效参数数”错误
EN

Stack Overflow用户
提问于 2020-09-03 15:54:39
回答 1查看 2.2K关注 0票数 0

我试图从谷歌应用程序脚本更新日历事件。我有日历ID、事件ID和试图作为变量更新的对象:

代码语言:javascript
复制
   var eventinfo = {
   "calendarId": calID
      "eventId": eventID,
      "resource": {
        "description": "1234"
      }
   };

 //update the event description and location

   var updater;
   try {
    updater = Calendar.Events.update(eventinfo);
    Logger.log('Successfully updated event: ' + i);
   } catch (e) {
    Logger.log('Fetch threw an exception: ' + e);
    } 

我得到了这个错误:

Fetch抛出一个异常:异常:提供的参数数无效。预期3-5

在此之前,我曾尝试以.update(calID, eventID, eventinfo)的方式调用update方法,其中事件信息是一个仅具有描述的对象,但返回的错误是错误调用。

我想我在我的目标论点中遗漏了一些东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-03 17:56:51

问题:

  • 首先,您在第一行和第二行之间的eventinfo定义中忘记了一个逗号。
  • 但是,我认为您的方法不起作用,因为您没有在event object函数中传递一个Calendar.Events.update()。结构应该是这样的: Calendar.Events.update(事件,calendarId,event.id );

解决方案/实例:

  • 下面的示例更新了以后的第一个事件。特别是,它更新标题(摘要)、描述和位置,但如果需要,可以随意修改: 函数updateNextEvent() { const calendarId =‘主’;const now =新日期();const events = Calendar.Events.list(calendarId,{ timeMin: now.toISOString(),singleEvents: true,orderBy:'startTime',maxResults: 1 });var event = events.items;//如果您想要event.location = 'The Coffee Shop';event.description = '1234';event.summary =‘新事件’,在这里使用您自己的事件对象;Event= Calendar.Events.update( event,calendarId,event.id );}

当然,不要忘记从Resources => Advanced 上打开Calendar API。

参考文献:

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

https://stackoverflow.com/questions/63727358

复制
相关文章

相似问题

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