How can I create a file in google drive "appDataFolder"?
I created google developer console settings which is necessary for creating file and accessing "appDataFolder".
Android Studio output error messages as below.
W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code": 403,
"errors": [
{
"domain": "global",
"message": "The granted scopes do not allow use of the Application Data folder.",
"reason": "insufficientScopes"
}
],
"message": "The granted scopes do not allow use of the Application Data folder."
}
W/System.err: 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.executeUnparsed(AbstractGoogleClientRequest.java:432)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.example.test1.MainActivity$3.run(MainActivity.java:131)
at java.lang.Thread.run(Thread.java:923)
Source code is
File body = new File();
body.setName(FILE_TITLE);//fileContent.getName());
body.setMimeType("text/plain");
body.setParents(Collections.singletonList("appDataFolder"));
File file = service.files().create(body, content)
.setFields("id")
.execute();
If the following line is commented out in the source code, my app can create a file in google drive top folder not "appDataFolder".
body.setParents(Collections.singletonList("appDataFolder"));
Android Studio 4.1.2 enter image description here
Best regards. Thanks in advance.
While from the looks of your developer console image you apear to have include a large number of scopes. The issue here is not with your settings in google developer console but rather with the scopes you have authorized your user with.
When you run your application the user is asked to consent to your accessing some of their data, this is the scope of authorization for your application. It defines what the user has granted your application access to do.
If your code only requests read only access then and you try to write to it then your going to see an insufficientScopes error message.
You need to check what scope is required of the method you are using and then make sure when you authorize your user that you are requesting that scope.
My guess is you have something like this
private static final List<String> SCOPES = Collections.singletonList(DriveScopes.DRIVE_METADATA_READONLY);
YOu need to include this scope https://www.googleapis.com/auth/drive.appdata
which is probably something like DriveScopes.DRIVE_APPDATA
Remember once the scopes have been changed in your application you will need to reauthorize the user. If your storing the consent then it needs to be removed in order to request authorization again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.