从Google云端硬盘下载PDF文件 [英] Download file as pdf from Google Drive
问题描述
我必须下载所有Google驱动器文件。我正试图遵循此
获取下载网址并使用此代码获取pdf url
i获取downloadurl使用
file.getDownloadUrl()
但是当我要求下载或转换为流时,它会抛出错误404:未找到。
我在哪里丢失..一些认证问题或一些超越.....
下载的东西我正在使用像这样...
InputStream tempstream = Temp.downloadFile(service,file);
和
private static InputStream downloadFile(Drive service,File file){
if(file.getDownloadUrl()!= null&& file.getDownloadUrl()。length()> 0){
尝试{
//下载网址是:https://doc-0s-9k-docs.googleusercontent.com/docs/securesc/6rpci9p5rgc1ards1udmrkv5oparm1a2/eoas3kt0uj6afg559kiugg3d6fftlere/1357740000000/06400000604443042302/18001816663358798513/0B2tdn0tkhMowTFVyRzYzaGhWeTQ?h=16653014193614665626& ; e = download& gd = true
HttpResponse resp =
service.getRequestFactory()。buildGetRequest(new GenericUrl(file.getDownloadUrl()))
.execute();
return resp.getContent();
} catch(IOException e){
//发生错误。
e.printStackTrace();
返回null;
}
}其他{
//文件没有存储在驱动器上的任何内容。
返回null;
}
}
downloadurl
请帮助...我感觉有些我无法通过正确的身份验证调用方法....
您必须确保:您的服务已获得授权
您的下载网址是新鲜的(因为它们到期)
否则您的代码是正确的。有关详情:
https:// developers.google.com/drive/manage-downloads
I have to download all Google drive files. i am trying to follow this for Getting download url and using this code for pdf url i am getting downloadurl using
file.getDownloadUrl()
but when i am calling for download or converting into stream it is throwing error 404: not found.
where i am missing .. some authentication issue or some thing beyond ..... for downloading i am using like this ...
InputStream tempstream = Temp.downloadFile(service, file);
and
private static InputStream downloadFile(Drive service, File file) {
if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
try {
//download url is : "https://doc-0s-9k-docs.googleusercontent.com/docs/securesc/6rpci9p5rgc1ards1udmrkv5oparm1a2/eoas3kt0uj6afg559kiugg3d6fftlere/1357740000000/06400000604443042302/18001816663358798513/0B2tdn0tkhMowTFVyRzYzaGhWeTQ?h=16653014193614665626&e=download&gd=true"
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;
}
}
downloadurl please help... i feel some i am not able to call method with proper authentication....
You must make sure:
- Your service is authorized
- Your download URL is fresh (because they expire)
Otherwise your code is correct. For more info:
https://developers.google.com/drive/manage-downloads
这篇关于从Google云端硬盘下载PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!