我正在尝试使用谷歌API从谷歌云端硬盘添加附件到谷歌日历。我尝试遵循以下代码,该代码可以正确执行,没有任何异常或错误,但未在日历事件中添加附件。
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();
}
}
谢谢雷努卡
Google.Apis.Drive.v3.Data.File f_file1 = null;
f_file1 = m_DriveService.Files.Get("fileID").Execute();
EventAttachment attach1 = new EventAttachment();
//attach.FileId = file.Id;
attach1.Title = f_file1.Name;
attach1.MimeType = f_file1.MimeType;
attach1.FileUrl = FileURL;
List<EventAttachment> listEveAttach1 = new List<EventAttachment>();
listEveAttach1.Add(attach1);
f_CalEventObj.Attachments = listEveAttach1;
m_CalService.Events.Insert(f_CalEventObj, obj_addedCal).SupportsAttachments = true;
EventsResource.InsertRequest obj_request = m_CalService.Events.Insert(f_CalEventObj, obj_addedCal);
obj_request.SupportsAttachments = true;
Google.Apis.Calendar.v3.Data.Event obj_AddedEvent = obj_request.Execute();
它工作正常..