[英]How can I give full permissions to Google Drive REST API?
I'm trying to create an app that copies and deletes existing spreadsheets. 我正在尝试创建一个复制和删除现有电子表格的应用。 I've set up the DriveQuickstart from https://developers.google.com/drive/v2/web/quickstart/java 我已经从https://developers.google.com/drive/v2/web/quickstart/java设置了DriveQuickstart
The error that I'm getting now is saying that I do not have sufficient permissions to access that, even after I click the "Allow" button that comes up on my browser after I run the sample. 我现在得到的错误是说我没有足够的权限来访问它,即使我在运行示例后点击浏览器上出现的“允许”按钮。
My code is exactly the same as on the quickstart link. 我的代码与快速入门链接完全相同。
I'm getting this stacktrace: 我得到这个堆栈跟踪:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}
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.execute(AbstractGoogleClientRequest.java:469)
at DriveQuickstart.main(DriveQuickstart.java:110)
To build on adjuremods response, this is what worked for me: 为了建立adjuremods响应,这对我有用:
1) Change this line: 1)改变这一行:
private static final List<String> SCOPES =
Arrays.asList(DriveScopes.DRIVE_METADATA_READONLY);
to: 至:
private static final java.util.Collection<String> SCOPES =
DriveScopes.all();
2) Delete your existing stored credentials so that it will fetch them again, and reexecute your program: 2)删除现有的存储凭据,以便再次获取它们,然后重新执行您的程序:
rm ~/.credentials/drive-java-quickstart/StoredCredential
Note: you want an OAuth Client ID called client_secret.json
file, not the client_id.json file (I think - that's what worked for me anyway). 注意:您需要一个名为client_secret.json
文件的OAuth客户端ID,而不是client_id.json文件(我认为 - 无论如何,这对我有用)。
Since you're using the exact code form the QuickStart, it may have something to do with the scope set, its currently set as DriveScopes.DRIVE_METADATA_READONLY
, which if you check out its meaning in the Choose Auth Scopes page, it states 由于您使用的是QuickStart中的确切代码,因此它可能与范围集有关,它当前设置为DriveScopes.DRIVE_METADATA_READONLY
,如果您在“ 选择身份验证范围”页面中查看其含义,则说明
Allows read-only access to file metadata, but does not allow any access to read or download file content 允许对文件元数据进行只读访问,但不允许任何读取或下载文件内容的访问权限
You can look at the cited page to know what scope it is you'll exactly use. 您可以查看引用的页面,了解它将使用的范围。 Its most likely going to be https://www.googleapis.com/auth/drive
, so check out the DriveScopes
class for the constant of the same nature. 它最有可能是https://www.googleapis.com/auth/drive
,因此请查看DriveScopes
类以获得相同性质的常量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.