我找不到添加附件到日历活动的方法。我希望应该有一个简单的方法,如下面的片段,
function createNewEvent()
{
var file = DriveApp.getFileById('1eqaThzYmTbZzP-my file id-rXrBrWDW8DwMNeU'); //get file to be attached
var title = 'Apollo 11 Landing';
var startTime = new Date('January 20, 2016 20:00:00 UTC');
var endTime = new Date('January 20, 2016 21:00:00 UTC');
var options = {description:'Sample description', location: 'The Moon', attachments:file}; //can we add attachments like this?
var event = CalendarApp.getDefaultCalendar().createEvent(title, startTime, endTime, options);
}
这可能吗?
答案 0 :(得分:7)
是的,这是可能的。首先,您必须enable Advanced Calendar Service。然后你可以做这样的事情:
function createNewEvent() {
var calendarId = ''; //Calendar Id String
var fileId = ''; // File Id String
var start = new Date('January 20, 2016 20:00:00 UTC');
var end = new Date('January 20, 2016 21:00:00 UTC');
var eventObj = {
summary: 'Apollo 11 Landing',
location: 'The Moon',
description: 'Sample description',
start: {dateTime: start.toISOString()},
end: {dateTime: end.toISOString()},
attachments: [{
'fileUrl': 'https://drive.google.com/open?id=' + fileId,
'title': 'Moon Docs'
}]
};
var resp = Calendar.Events.insert(eventObj, calendarId, {'supportsAttachments': true});
Logger.log(resp); // Check out the response in the logs!
}
如需更多选项,请查看Events documentation。