下面链接的页面上列出的解决方案不包括此主题:https://developers.google.com/drive/web/manage-downloads
答案 0 :(得分:0)
经过一番尝试和错误后我得到了这段代码:
String odt = file.getExportLinks().get("application/pdf");
try (FileOutputStream fos = new FileOutputStream("C:/data/test_" + file.getTitle() + ".pdf")) {
service.files().get(file.getId()).getMediaHttpDownloader().download(new GenericUrl(odt), fos);
} catch (IOException ioe) {
ioe.printStackTrace();
}
以下是两种选择:
public static InputStream download(Drive service, String url) throws IOException {
return service.getRequestFactory().buildGetRequest(new GenericUrl(url)).execute().getContent();
}
public static void download(Drive service, String url, OutputStream os) throws IOException {
HttpRequestFactory rf = service.getRequestFactory();
new MediaHttpDownloader(rf.getTransport(), rf.getInitializer()).download(new GenericUrl(url), os);
}
但我确实想知道是否有更多惯用的方式来获取MediaHttpDownloader。
PS:我认为应该将正确的方法添加到Google文档页面中。