What's new

When usingGoogle Drive, how to grant permission for a Java application using the SDK to download binary files

Fever

Active member
Staff member
I have written a Java application using Google's SDK v3 and Java 8 to download binary files from Google Drive (not Google doc or sheets or anything like - binary files I uploaded there). My app has no trouble listing the files, but when I try to download one I get a permissions error:

Exception in thread "main" com.google.api.client.http.HttpResponseException: 403 Forbidden
{
"error": {
"errors": [
{
"domain": "global",
"reason": "appNotAuthorizedToFile",
"message": "The user has not granted the app 38578455738 read access to the file 1acfVsq9dUUYuk6q9gM69aWVasvdfr.",
"locationType": "header",
"location": "Authorization"
}
],
"code": 403,
"message": "The user has not granted the app 38578455738 read access to the file 1acfVsq9dUUYuk6q9gM69aWVasvdfr."
}
}


The code that attempts to download is:

String fileId = "1acfVsq9dUUYuk6q9gM69aWVasvdfr";
OutputStream outStream = new ByteArrayOutputStream();
service.files().get(fileId).executeMediaAndDownloadTo(outStream);


My questions are:

How do I know that my app is 38578455738?

How do I grant it (or anyone) permission to download?

I have tried using the Google Drive web interface to share with "anyone" but that didn't help.

Continue reading...
 
Top