通过Google Apps脚本在日历上创建带有附件的事件 [英] Create an event with an attachment on Calendar via Google apps script

查看:98
本文介绍了通过Google Apps脚本在日历上创建带有附件的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到将附件添加到日历活动的方法.我希望应该像下面的代码片段一样简单,

I couldn't find a way to add an attachment to my calendar event. I hope there should be a simple way like below snippet,

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);
}

这可能吗?

推荐答案

是的,这是可能的.首先,您必须启用

Yes, this is possible. First you must enable the Advanced Calendar Service. Then you can do something like this:

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!
}

有关更多选项,请查看事件文档.

For more options, check out the Events documentation.

这篇关于通过Google Apps脚本在日历上创建带有附件的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆