繁体   English   中英

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

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

我正在尝试使用Google Drive API从驱动器下载文件

重现步骤:步骤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);
    }

根据您得到的错误...

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

尝试在您的GET请求中添加“?alt = media”。 我的猜测是您在输入参数中缺少某些内容,或者可能无权访问媒体(也许未登录?)。 如果看不到您尝试调用的实际代码或发出的请求,我将无济于事。

暂无
暂无

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

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