我想使用谷歌应用程序脚本发送谷歌日历邀请,但我在以下代码片段的最后一行遇到错误:
function testnotification(){
var calendarId = "####";
var eventId = "###";
var email = ""###@gmail.com
addGuestAndSendEmail(calendarId,eventId,email)
}
function addGuestAndSendEmail(calendarId, eventId, newGuest) {
var calendar = CalendarApp.getCalendarById(calendarId);
var event = calendar.getEventById(eventId);
var attendees = [];
attendees.push({email: newGuest});
var resource = { attendees: attendees };
var args = { sendUpdates: "all" };
calendar.createEvent.patch(resource, calendarId, eventId, args);
}
我已经将最后一行从
Calendar.Events.patch(event, calendar, event.id, args);
修改为calendar.createEvent.patch(resource, calendarId, eventId, args)
,但是当我运行时,它说:
calendar.createEvent.patch 不是函数
我查看了 stackoverflow 问题(Q1,Q2)但找不到方法。关于如何解决
patch
错误的任何指导?
在@Tanaike 回答之后,我在以下脚本中仍然遇到错误:
function testNotification(){
var calendarId = "###";
var eventId = "###";
var email = "###@gmail.com"
addGuestAndSendEmail(calendarId,eventId,email)
}
function addGuestAndSendEmail(calendarId, eventId, newGuest) {
Calendar.Events.patch({ attendees: [{ email: newGuest }] }, calendarId, eventId, { sendUpdates: "all" });
}
我认为
calendar.createEvent.patch(resource, calendarId, eventId, args);
不正确。我想你这期calendar.createEvent.patch is not a function
的原因就是因为这个。如果你想达到你的目的,下面的修改怎么样?
这次修改,你的
addGuestAndSendEmail
被修改了
function addGuestAndSendEmail(calendarId, eventId, newGuest) {
Calendar.Events.patch({ attendees: [{ email: newGuest }] }, calendarId, eventId, { sendUpdates: "all" });
}
calendarId, eventId, newGuest
的值是有效值时,发送电子邮件至newGuest
.