google-apps-script - 尝试更新事件时出现“无效的参数数量”错误
问题描述
我正在尝试从谷歌应用脚本更新日历事件。我有日历 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 抛出异常:异常:提供的参数数量无效。预计仅 3-5
以前,我曾尝试以这种方式调用更新方法.update(calID, eventID, eventinfo)
,其中事件信息是一个只有描述的对象,但返回的错误是错误调用。
我想我在我的对象论点中遗漏了一些东西。
解决方案
问题:
首先,您在
eventinfo
第一行和第二行之间的定义中忘记了逗号。但是,我认为您的方法行不通,因为您没有
event object
在Calendar.Events.update()
函数中传递 an 。结构应该是这样的:Calendar.Events.update( event, calendarId, event.id );
解决方案/示例:
以下示例更新了未来的第一个事件。特别是,它会更新标题(摘要)、描述和地点,但如果您愿意,可以随意修改:
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 ); }
当然,不要忘记从Resources => Advanced Google services打开 Calendar API 。
参考:
推荐阅读
- c - “%lld\n”是什么意思?
- spring - Spring OAuth2 - 如何使用 /oauth/authenticate 端点?
- javascript - 根据 CSV 值切换可见性
- react-native - 键盘可见时无法单击按钮-本机反应
- atlassian-sourcetree - 适用于 Windows 的 SourceTree v3.2.6 显示所有关闭的分支
- javascript - 如何测试 es6 默认值
- node.js - 您如何从 Node/Express REST 端点流式传输结果,但每个返回的文档都有延迟?
- typescript - 如何在 onCreate() Firebase Cloud Code 监听器中未定义初始值?
- angular - 我如何替换Angular ngx-charts中图表的“图例”字?
- php - Auth::attempt 在 Laravel 5.8 中不起作用