0
我正在尝试使用谷歌apis从谷歌驱动器添加谷歌日历附件。我试着下面的代码正确执行,没有任何异常或错误,但附件不会被添加到日历事件中。向Google日历添加附件
private void addattachment(String eveID, String fileID, string Calid)
{
try
{
Google.Apis.Calendar.v3.Data.Event f_event = m_CalService.Events.Get(Calid, eveID).Execute();
Google.Apis.Drive.v3.Data.File f_File = m_DriveService.Files.Get(fileID).Execute();
List<EventAttachment> f_ListEventAttach = (List<EventAttachment>)f_event.Attachments;
if (f_ListEventAttach == null)
f_ListEventAttach = new List<EventAttachment>();
f_ListEventAttach.Add(new EventAttachment()
{ FileUrl = FileUrl,
MimeType = f_File.MimeType,
Title = f_File.Name}
);
Google.Apis.Calendar.v3.Data.Event newEvent = new Google.Apis.Calendar.v3.Data.Event();
newEvent.Attachments = f_ListEventAttach;
m_CalService.Events.Patch(newEvent, Calid, eveID).SupportsAttachments = true;
m_CalService.Events.Patch(newEvent, Calid, eveID).Execute();
}
}
谢谢 雷努卡
我的猜测是,m_CalService.Events.Patch(newEvent,CALID,eveID).Execute();实际上并没有将supportsAttachments设置为true。我首先切换到更新而不是补丁。然后我将更新请求保存到一个变量中,在该变量上设置supportsAttachments,然后调用相同变量的执行。 – luc