"Invalid number of arguments" 尝试更新活动时出错

"Invalid number of arguments" error when trying to update an event

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

   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 threw an exception: Exception: Invalid number of arguments provided. Expected 3-5 only

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

我想我的对象参数中遗漏了一些东西。

问题:

  • 首先,你在eventinfo的定义中忘记了一个逗号 在第一行和第二行之间。

  • 但是,我认为你的方法行不通,因为你不 在 Calendar.Events.update() 函数中传递一个 event object。结构应该是这样的:

    Calendar.Events.update(
       event,
       calendarId,
       event.id
     ); 
    

Solution/Example:

  • 以下示例更新了未来的第一个事件。在 特别是,它会更新标题(摘要)、描述和位置,但 如果需要,请随意修改:

    function updateNextEvent() {
      const calendarId = 'primary';
      const now = new Date();
      const events = Calendar.Events.list(calendarId, {
        timeMin: now.toISOString(),
        singleEvents: true,
        orderBy: 'startTime',
        maxResults: 1
      });
    
     var event = events.items[0]; //use your own event object here if you want
    
     event.location = 'The Coffee Shop';
     event.description = '1234';
     event.summary = 'New event';
     event = Calendar.Events.update(
          event,
          calendarId,
          event.id
        ); 
    }
    

当然,不要忘记从资源 => 高级Google服务[=打开日历API 44=].

参考文献: