Google 日历 API android 创建活动
Google Calendar API android create event
我正在尝试在 android 带有 Google 日历 API 的应用程序中使用文件 a (.pdf) 创建一个事件 API: Create Events
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()));
在 Drive: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,您需要获取驱动文件的元数据。首先获取 Drive 文件,然后获取 Meta 数据。元数据对象具有所有 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();
我正在尝试在 android 带有 Google 日历 API 的应用程序中使用文件 a (.pdf) 创建一个事件 API: Create Events
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()));
在 Drive: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,您需要获取驱动文件的元数据。首先获取 Drive 文件,然后获取 Meta 数据。元数据对象具有所有 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();