我一直在尝试使用Mediahttpdownloader下载文件并传递文件的webcontentlink。但是,它总是因401未经授权而失败。
MediaHttpDownloader downloader = new MediaHttpDownloader(httpTransport, drive.getRequestFactory().getInitializer());
downloader.download(new GenericUrl(file.getWebContentLink()), out);
我尝试添加授权标头,但仍然失败:
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAuthorization("Bearer "+ credential.getAccessToken());
downloader.download(new GenericUrl(file.getWebContentLink(), requestHeaders, out);
我还尝试将访问令牌添加到URL,但仍未通过401未授权。
downloader.download(new GenericUrl(file.getWebContentLink()+"?access_token=ACCESS_TOKEN"), out);
这是确切的错误:
401 Unauthorized
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
知道如何将Webcontent Link与Mediahttpdownloader类一起使用吗?