I am trying to download a file from google drive I created google credentials oath and all,
I am perfectly able to get the list of files on the drive However, when I try to download a file, i get error 500
this is my code to download:
private static void downloadFile(Drive service,String fileId) {
try {
OutputStream outputStream = new FileOutputStream("test.csv");
service.files().export(fileId, "text/csv")
.executeMediaAndDownloadTo(outputStream);
} catch (IOException e) {
// An error occurred.
e.printStackTrace();
}
}
And this is the resulting response:
com.google.api.client.http.HttpResponseException: 500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError"
} ],
"message" : "Internal Error"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMedia(AbstractGoogleClientRequest.java:380)
at com.google.api.services.drive.Drive$Files$Export.executeMedia(Drive.java:2464)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAsInputStream(AbstractGoogleClientRequest.java:523)
at com.google.api.services.drive.Drive$Files$Export.executeMediaAsInputStream(Drive.java:2459)
at com.mobile.stringExtractor.core.DriveQuickstart.downloadFile(DriveQuickstart.java:158)
at com.mobile.stringExtractor.core.DriveQuickstart.main(DriveQuickstart.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
I have no clue why it try to do something with json when i am trying to download a google sheet file.
A few notes:
1. the file does exist and is not empty
2. I did authorize google drive for the said account with scopes DriveScopes.Drive
3. I do manage to download the list of files just fine
How can I fix this problem?