我正在尝试使用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.i出现此错误: “代码”: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);
}
答案 0 :(得分:0)
根据你得到的错误......
https://developers.google.com/drive/v3/web/manage-downloads
尝试在您的GET请求中添加“?alt = media”。我的猜测是你在输入参数中遗漏了某些内容,或者可能无法访问媒体(可能没有登录?)。如果没有看到您试图拨打的实际代码或您正在提出的请求,我将无法提供更多帮助。