我正在尝试使用Google Calendar API在安卓应用程序中创建一个带有文件a (.pdf)的事件: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()));
发布于 2017-03-31 08:05:28
在驱动器中:V3不退出getALternateLink()在应用程序中将de版本更改为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'
}
发布于 2018-03-29 09:44:49
对于驱动接口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();
https://stackoverflow.com/questions/43066934
复制