简体   繁体   English

如何授予Google Drive REST API完全权限?

[英]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.

相关问题 如何使用Jersey调用Google Drive REST API? - How to invoke Google Drive REST API with Jersey? 如何使用 Google Drive API (Java) 解决 403 用户权限错误 - How to solve 403 User Permissions error with Google Drive API (Java) 如何上传带有链接的文件到Google Drive REST API v2 - How to upload a file with a link to Google Drive REST API v2 如何使用 rest api 从谷歌驱动器读取 json - How to read json from google drive with rest api Google Drive api - com.google.api.services.drive.Drive.files() - File 对象都没有权限? - Google drive api - com.google.api.services.drive.Drive.files() - None of the File objects have permissions? 如何使用 Google Drive API v3 获取 Google 电子表格文件 ID? - How can I get Google spreadsheets file Id by using Google drive API v3? Google云端硬盘权限列表剩余调用不会返回所有权限 - Google Drive permission list rest call does not return all permissions 如何使用Java Drive Rest V2 API从Google Drive获取文档和文件的绝对路径? - How to get absolute path of a document and file from Google Drive Using Java Drive Rest V2 API? Google云端硬盘:通过REST API下载gsheets - Google Drive : gsheets download through REST API 使用 Google Sheets / Google Drive API 请求特定的文件权限 - Request specific file permissions with Google Sheets / Google Drive API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM