0

我真的试图创建与Android应用程序文件(.PDF)与谷歌日历API一个事件:Create Events谷歌日历API的Android创建事件

public static void addAttachment(Calendar calendarService, Drive driveService, String calendarId, 
    String eventId, String fileId) throws IOException { 
    File file = driveService, android .files().get(fileId).execute(); 
    Event event = calendarService.events().get(calendarId, eventId).execute(); 

    List<EventAttachment> attachments = event.getAttachments(); 
    if (attachments == null) { 
    attachments = new ArrayList<EventAttachment>(); 
    } 
    attachments.add(new EventAttachment() 
     .setFileUrl(file.getAlternateLink()) 
     .setMimeType(file.getMimeType()) 
     .setTitle(file.getTitle())); 

    Event changes = new Event() 
     .setAttachments(attachments); 
    calendarService.events().patch(calendarId, eventId, changes) 
     .setSupportsAttachments(true) 
     .execute(); 
} 

我复制完全以这一点,但它不工作,机器人工作室把红色getAlternateLink()和的getTitle()犯规reconize,具体线路:

attachments.add(new EventAttachment() 
     .setFileUrl(file.getAlternateLink()) 
     .setMimeType(file.getMimeType()) 
     .setTitle(file.getTitle())); 
+1

究竟不起作用?任何例外? – pritaeas

+0

Android Studio放入了红色getAlternateLink()和getTitle() –

+0

从您复制代码的文档中可以看出[这里](https://developers.google.com/google-apps/calendar/create-events ):“在将附件支持添加到本地存储事件的现有应用程序中时,必须在启用用于修改事件的'supportsAttachments'参数之前对所有事件执行完全同步,如果您不先执行同步,则可能会无意中删除现有附件来自用户的事件。“另外请注意,您正在执行的代码演示了如何更新现有事件以添加附件。 – KENdi

回答

0

驱动器:V3犯规出口getALternateLink()的变化去版本的应用程序到V2

// compile('com.google.apis:google-api-services-drive:v3-rev64-1.22.0') { 
//  exclude group: 'org.apache.httpcomponents' 
// } 

把这个

compile('com.google.apis:google-api-services-drive:v2-rev123-1.18.0-rc'){ 
    exclude group: 'org.apache.httpcomponents' 
}