【问题标题】:Java :Not able to download spreadsheet using google drive APIJava:无法使用 Google Drive API 下载电子表格
【发布时间】:2017-03-01 07:18:20
【问题描述】:

我正在尝试使用 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”,然后单击执行。我收到此错误: “代码”: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);
    }

【问题讨论】:

  • 嗯,你的问题不清楚☹
  • 我使用googleapis.com/drive/v3/files{fileid}/export 下载了一个文件。我提供了输入参数文件 ID 和 mime 类型。我得到了错误请求的响应
  • 你的代码在哪里?
  • 我已经使用了这个链接developers.google.com/drive/v3/reference/files/export#try-it。从这里我得到 403 错误代码。这是我的代码,从代码中我也得到 403 错误代码。我如何粘贴代码,因为它超出了限制,所以这里不接受整个代码
  • @SuvarnaLakshmiGodavarthy,只需编辑您的问题以添加您的代码。

标签: java


【解决方案1】:

根据您遇到的错误...

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

尝试将“?alt=media”添加到您的 GET 请求中。我的猜测是您在输入参数中遗漏了某些内容,或者可能无法访问媒体(可能没有登录?)。如果没有看到您尝试调用的实际代码或您提出的请求,我将无能为力。

【讨论】:

  • 我如何在此处发布代码,因为我尝试发布时超出了限制
猜你喜欢
  • 2012-07-22
  • 2017-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多