我正在上传Word文档:
com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
body.setTitle(file.getName());
body.setMimeType(mimeType);
FileContent mediaContent = new FileContent(mimeType, file);
com.google.api.services.drive.model.File uploadedFile = service.files()
.insert(body, mediaContent).execute();
String downloadUrl = file.getExportLinks().get(mimeType);
上传很顺利。但是,对file.getExportLinks()的调用返回null,因此,此行为空指针。有人知道为什么getExportLinks()返回null吗?
答案 0 :(得分:0)
抓取文档密钥并创建如下链接:
Drive driveService = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).build();
File file = driveService.files().get(this.spreadsheetKey).execute();
String downloadUrl = file.getExportLinks().get("application/pdf");
示例downloadUrl: https://docs.google.com/feeds/download/spreadsheets/Export?key=的 somekey 强>&安培; exportFormat = PDF
注意:您可以将上述网址粘贴到浏览器中,只要您登录到Google云端硬盘,它就会下载。
不知道是否可以在没有文档密钥的情况下创建链接。
答案 1 :(得分:0)
您需要设置正确的Scope
才能访问链接。