簡體   English   中英

驅動器API錯誤下載文件

[英]Drive api error download a file

嘗試下載文件時出現錯誤,我無法從雲端硬盤下載文件。

這是我使用的代碼

private static InputStream downloadFile(String token, File file) {
Drive service = getDriveService(getCredential(token));

if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
  try {
    HttpResponse resp =
        service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
            .execute();
    return resp.getContent();
  } catch (IOException e) {
    // An error occurred.
    e.printStackTrace();
    return null;
  }
} else {
  // The file doesn't have any content stored on Drive.
  return null;
}

}

而我得到這個錯誤

GET /a/thotz.net/uc?id=xxxxx&export=download HTTP/1.1
Host: docs.google.com
Content-length: 0
Authorization: OAuth ya29.AHES6ZTruwaMm_SHZAb9LFMCbxiJ85vaDccbil-h4enw
HTTP/1.1 401 Unauthorized
Content-length: 147
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Reason: Unauthorized
Via: HTTP/1.1 GWA
X-chromium-appcache-fallback-override: disallow-fallback
Cache-control: private, max-age=0
Date: Thu, 25 Apr 2013 19:54:12 GMT
X-frame-options: SAMEORIGIN
Content-type: text/html; charset=UTF-8
Expires: Thu, 25 Apr 2013 19:54:12 GMT
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

我在其他請求中測試令牌,它是否有效,所以不知道為什么當我嘗試下載文件時顯示401錯誤。

我在使用PHP庫時遇到了類似的問題-原來您需要通過身份驗證進行請求-401錯誤表示您未通過身份驗證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM