【发布时间】:2021-05-30 05:30:33
【问题描述】:
如何在谷歌驱动器“appDataFolder”中创建文件?
我创建了创建文件和访问“appDataFolder”所必需的谷歌开发者控制台设置。
Android Studio 输出错误信息如下。
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)
源码是
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();
如果在源代码中注释掉以下行,我的应用可以在 google drive 中创建文件 顶级文件夹不是“appDataFolder”。
body.setParents(Collections.singletonList("appDataFolder"));
Android Studio 4.1.2 enter image description here
最好的问候。 提前致谢。
【问题讨论】:
标签: java android-studio google-drive-api google-oauth google-api-java-client