如何使用Apps脚本获取Google日历事件附件 [英] How to get Google calendar event attachment using Apps Script

查看:68
本文介绍了如何使用Apps脚本获取Google日历事件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have written a Google Apps Script which successfully attaches a Google Sheets document to a newly created Calendar Event. The following code shows how this is achieved:

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.

This all works perfectly. I am now writing a script to iterate all events over a certain time period, and grab those attached file ID's.

我能够成功获取我要关注的事件,但是无法访问随附的Google表格的ID.

I am able to successfully get the events I am after, but am having trouble accessing the ID of the attached Google Sheet.

日历API文档似乎告诉我这是可能的.摘自文档:

The Calendar API Documentation appears to tell me this is possible. This is taken from the documentation:

[attachments [] .fileId,字符串]:附件的ID.只读. 对于Google云端硬盘文件,这是云端硬盘API中相应文件"资源条目的ID.

[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的方法,将不胜感激!

If anyone could help me put this all together and show me a way to grab the ID of the attached Google Sheet, it would be greatly appreciated!

谢谢:)

瑞安

推荐答案

您要从事件中检索文件ID.如果我的理解是正确的,那么该示例脚本怎么样?

You want to retrieve file IDs from an event. If my understanding is correct, how about this sample script?

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和文件名,请对fields使用attachments(fileId,title).
  • Note :

    • This sample script supposes that you have already known the event ID. If you need the method for retrieving the event IDs. Please tell me.
    • If you want to retrieve the file ID and filename of the attachment file, please use attachments(fileId,title) for fields.
      • Calendar.Events.get
      • fields

      如果我误解了你的问题,对不起.

      If I misunderstand your question, I'm sorry.

      这篇关于如何使用Apps脚本获取Google日历事件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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