问题
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....
回答1:
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
来源:https://stackoverflow.com/questions/14232487/download-file-as-pdf-from-google-drive