2013-04-25 178 views
1

试图下载文件出现错误,我无法从驱动器下载文件。驱动器api错误下载文件

下面是我用

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错误。

+0

你使用'drive.file'作用域吗?有一个我们即将修复的已知错误。否则你的代码对我来说看起来很好。 – 2013-04-29 20:12:30

回答

0

我有类似的问题,使用PHP库 - 事实证明,你需要使你的请求与身份验证 - 401错误意味着你没有进行身份验证。