javascript - 如何使用 Apps 脚本获取 Google 日历事件附件

标签 javascript google-apps-script google-calendar-api

我编写了一个 Google Apps 脚本,它成功地将 Google 表格文档附加到新创建的日历事件。以下代码显示了这是如何实现的:

var eventObj = { 
    summary: eventName,
    start: {dateTime: startDate.toISOString()},
    end: {dateTime: endDate.toISOString()},
    attachments: [{
      'fileUrl': 'https://drive.google.com/open?id=' + fileID,
      'title' : 'Booking Sheet'
    }]
  };
  
  Calendar.Events.insert(eventObj, inStorePartiesCalendarID, {'supportsAttachments': true});

这一切都很完美。我现在正在编写一个脚本来迭代特定时间段内的所有事件,并获取那些附加的文件 ID。

我能够成功获得我想要的事件,但无法访问随附的 Google 表格的 ID。

Calendar API Documentation似乎告诉我这是可能的。这取自文档:

[attachments[ ].fileId, string] : ID of the attached file. Read-only. For Google Drive files, this is the ID of the corresponding Files resource entry in the Drive API.

如果有人可以帮助我将所有这些放在一起并向我展示一种获取所附 Google 表格 ID 的方法,将不胜感激!

谢谢:)

瑞安

最佳答案

您想从事件中检索文件 ID。如果我的理解是正确的,这个示例脚本怎么样?

示例脚本:

var inStorePartiesCalendarID = "### calendar ID ###";
var eventId = "### Event ID ###";
var res = Calendar.Events.get(inStorePartiesCalendarID, eventId, {fields: "attachments/fileId"});
var fileIds = res.attachments.map(function(e){return e.fileId});
Logger.log(fileIds)

注意事项:

  • 此示例脚本假设您已经知道事件 ID。如果您需要检索事件 ID 的方法。请告诉我。
  • 如果要检索附件文件的文件 ID 和文件名,请使用 attachments(fileId,title) 作为 fields

引用:

如果我误解了你的问题,我很抱歉。

关于javascript - 如何使用 Apps 脚本获取 Google 日历事件附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49995649/

相关文章:

google-apps-script - 谷歌脚本 : Define Variable from Library

google-apps-script - Google Apps 脚本页面未打开

java - 我应该如何在 Gentics Mesh 中实现包含重复事件的日历?

javascript - 如何在 map 呈现后以编程方式更改 Google map 标记图标

javascript - JS : how to listen event after template contruction?

javascript - 通过ajax、php、jquery传递checkbox的值

android - 如何在 Android 中为用户的日历创建或添加不可编辑的事件?

javascript - 将jquery修改应用于meteor站点

javascript - 整理出所有含有 'unread = true'的消息

android - 在应用程序中显示 Google 日历