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