簡體   English   中英

Google Calendar API android create event

[英]Google Calendar API android create event

我正在嘗試使用Google Calendar API在android App中使用文件(.pdf) 創建事件創建事件

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();
}

我完全復制了此內容,但它不起作用,Android Studio放入紅色的getAlternateLink()和getTitle()不重新協調,特別是以下行:

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

在雲端硬盤中: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'
}

對於Drive API V3,您需要獲取驅動器文件的元數據。 首先獲取驅動器文件,然后獲取元數據。 元數據對象具有所有3個值。

Task<Metadata> metadataTask = getDriveResourceClient().getMetadata(driveFile.getDriveId().asDriveResource());

Tasks.await(metadataTask);
Metadata meta =  metadataTask.getResult();

Event event = mService.events().get(calendarId, eventId).execute();
List<EventAttachment> attachments = event.getAttachments();
if (attachments == null) {
    attachments = new ArrayList<>();
}

Event changes = new Event();
attachments.add(new EventAttachment()
        .setFileUrl(meta.getAlternateLink())
        .setMimeType(meta.getMimeType())
        .setTitle(meta.getTitle()));
changes.setAttachments(attachments);

mService.events()
        .patch(calendarId, eventId, changes)
        .setSupportsAttachments(true)
        .execute();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM