【问题标题】:Downloading files from google drive从谷歌驱动器下载文件
【发布时间】:2016-01-08 19:13:58
【问题描述】:

我正在尝试从谷歌驱动器下载文件 我创建了谷歌凭据誓言和所有,

我完全能够获取驱动器上的文件列表 但是,当我尝试下载文件时,出现错误 500

这是我要下载的代码:

  private static void downloadFile(Drive service,String fileId) {
    try {

        OutputStream outputStream = new FileOutputStream("test.csv");
        service.files().export(fileId, "text/csv")
                .executeMediaAndDownloadTo(outputStream);

    } catch (IOException e) {
        // An error occurred.
        e.printStackTrace();
    }
}

这是得到的响应:

    com.google.api.client.http.HttpResponseException: 500 Internal Server Error
{
  "code" : 500,
  "errors" : [ {
    "domain" : "global",
    "message" : "Internal Error",
    "reason" : "internalError"
  } ],
  "message" : "Internal Error"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMedia(AbstractGoogleClientRequest.java:380)
    at com.google.api.services.drive.Drive$Files$Export.executeMedia(Drive.java:2464)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAsInputStream(AbstractGoogleClientRequest.java:523)
    at com.google.api.services.drive.Drive$Files$Export.executeMediaAsInputStream(Drive.java:2459)
    at com.mobile.stringExtractor.core.DriveQuickstart.downloadFile(DriveQuickstart.java:158)
    at com.mobile.stringExtractor.core.DriveQuickstart.main(DriveQuickstart.java:138)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

我不知道为什么当我尝试下载 google sheet 文件时它会尝试使用 json 做某事。

A few notes:
1. the file does exist and is not empty
2. I did authorize google drive for the said account with scopes DriveScopes.Drive
3. I do manage to download the list of files just fine

我该如何解决这个问题?

【问题讨论】:

  • 能不能打开日志然后粘贴http请求

标签: java google-drive-api


【解决方案1】:

documentation 中所写,表示服务器暂时可用。对于这种错误,您只需实现exponential backoff 即可重新发送请求。

这个想法是服务器只是暂时不可用,当它们试图恢复时它们不应该被压垮。

默认实现要求 500 和 503 状态代码回退。如果需要不同的状态代码,子类可能会覆盖。

【讨论】:

    猜你喜欢
    • 2021-04-05
    • 2018-07-21
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多