简体   繁体   English

Java Google Drive API下载文件

[英]Java Google Drive API download file

I am trying to download file with Drive Api and get some trouble. 我正在尝试使用Drive Api下载文件并遇到一些麻烦。 I read this guide downloading file with Drive Api v3 and use this code 我阅读了本指南以及Drive Api v3的下载文件,并使用了此代码

String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId).executeMediaAndDownloadTo(outputStream);

Every time I am getting this error ` 每当我收到此错误时,

com.google.api.client.http.HttpResponseException: 400 Bad Request
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}`

From Errors and suggested actions : 错误和建议的操作

Error encountered can mean that a required field or parameter has not been provided, the value supplied is invalid, or the combination of provided fields is invalid. 遇到错误可能意味着未提供必填字段或参数,提供的值无效或提供的字段组合无效。

This error can be thrown when trying to add a duplicate parent to a Drive item. 尝试将重复的父项添加到驱动器项时,可能会引发此错误。 It can also be thrown when trying to add a parent that would create a cycle in the directory graph. 尝试添加将在目录图中创建循环的父项时,也可能引发该异常。

You may also try solution advised in Google API for Google Docs, requesting a list of documents — 400 Bad Request wherein specifying correct version number in your HTTP GET request could be possible solution for the encountered error. 您也可以尝试使用Google API for Google Docs中建议的解决方案,请求一个文档列表-400错误请求,其中在HTTP GET请求中指定正确的版本号可能是解决所遇到的错误的方法。

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

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