我正在为日历使用谷歌脚本,并尝试使用他们的示例。但是当我运行下面的代码时,它一直说不能调用null的方法“createEvent”。其实我不是很了解这里的回调函数。所以它要么是一般的 js 问题,要么是 google 脚本问题。
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
};
这是整个代码:
function createEvent() {
/*var cal = CalendarApp.getCalendarById(calendarId);*/
var cal = CalendarApp.getAllOwnedCalendars()[0];
var title = 'Script Demo Event';
var start = new Date("October 26, 2013 08:00:00 EST");
var end = new Date("October 26, 2013 10:00:00 EST");
var desc = 'Created using Google Apps Script';
var loc = 'Script Center';
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
};
function doGet() { // A script with a user interface that is published as a web app
// must contain a doGet(e) function.
// Create the UiInstance object myapp and set the title text
var myapp = UiApp.createApplication().setTitle('Here is the title bar');
// Create a button called mybutton and set the button text
var mybutton = myapp.createButton('Here is a button');
var handler = myapp.createServerHandler('createEventInvitePeople');
mybutton.addClickHandler(handler);
// Create a vertical panel called mypanel and add it to myapp
var mypanel = myapp.createVerticalPanel();
// Add mybutton to mypanel
mypanel.add(mybutton);
// Add my panel to myapp
myapp.add(mypanel);
// return myapp to display the UiInstance object and all elements associated with it.
return myapp;
}
/**
* Creates an event, invite guests, book rooms, and sends invitation emails.
* For more information on using Calendar events, see
* https://developers.google.com/apps-script/class_calendarevent.
*/
function createEventInvitePeople() {
var calId = CalendarApp.getAllOwnedCalendars()[0];
var room1CalId = 'a_room_cal_id';
var room2CalId = 'another_room_cal_id';
var guest1Email = 'XXX@gmail.com';
var guest2Email = 'XXX@gmail.com';
var invitees = room1CalId + ',' + room2CalId + ',' + guest1Email + ',' +
guest2Email;
var cal = CalendarApp.getCalendarById(calId);
var title = 'Script Center Demo Event';
var start = new Date("October 30, 2012 08:00:00 PDT");
var end = new Date("October 30, 2012 10:00:00 PDT");
var desc = 'Created using Apps Script';
var loc = 'Script Center';
var send = 'true';
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc,
guests : invitees,
sendInvites : send
});
};
谁能帮我一个忙?