简体   繁体   English

Java:无法使用Google Drive API下载电子表格

[英]Java :Not able to download spreadsheet using google drive API

I am trying to download a file from the drive using google drive api 我正在尝试使用Google Drive API从驱动器下载文件

Steps to reproduce : Step 1: Click on : https://developers.google.com/drive/v3/reference/files/export#try-it Step 2: I have provided fileid and mimetype I gave fileid and mime type as "application/vnd.google-apps.spreadsheet" and click on execute.i got this error: "code":403, "message":"Export requires alt=media to download the exported content." 重现步骤:步骤1:单击: https : //developers.google.com/drive/v3/reference/files/export#try-it步骤2:我提供了fileid和mimetype我将fileid和mime类型指定为“ “ application / vnd.google-apps.spreadsheet”,然后单击execute。我收到此错误:“ code”:403,“ message”:“导出需要alt = media才能下载导出的内容。”

public static void downloadFile(Drive service,String fileId) throws IOException{
        OutputStream outputStream = new ByteArrayOutputStream();
        //OutputStream outputStream = new FileOutputStream("/Users/xxxxx/Downloads/driveFile.xls");
        //service.get 
        service.files().export(fileId,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
        .executeMediaAndDownloadTo(outputStream);
    }

Based on the error you are getting... 根据您得到的错误...

https://developers.google.com/drive/v3/web/manage-downloads https://developers.google.com/drive/v3/web/manage-downloads

Try adding "?alt=media" to your GET request. 尝试在您的GET请求中添加“?alt = media”。 My guess is you are missing something in the input parameters or possibly do not have access to the media (not logged in maybe?). 我的猜测是您在输入参数中缺少某些内容,或者可能无权访问媒体(也许未登录?)。 I can't help more without seeing the actual code you are attempting to call, or the request you are making. 如果看不到您尝试调用的实际代码或发出的请求,我将无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM