【问题标题】:How can I give full permissions to Google Drive REST API?如何授予 Google Drive REST API 的完全权限?
【发布时间】:2016-05-20 01:30:57
【问题描述】:

我正在尝试创建一个复制和删除现有电子表格的应用。我已经从 https://developers.google.com/drive/v2/web/quickstart/java 设置了 DriveQuickstart

我现在遇到的错误是说我没有足够的权限来访问它,即使在我运行示例后单击浏览器上出现的“允许”按钮后也是如此。

我的代码与快速入门链接上的代码完全相同。

我得到了这个堆栈跟踪:

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)

【问题讨论】:

  • 我也有这个问题。我没有看到应该在哪里添加范围。

标签: java oauth-2.0 google-api google-drive-api google-admin-sdk


【解决方案1】:

要建立在 adjuremods 响应的基础上,这对我有用:

1) 改变这一行:

private static final List<String> SCOPES =
    Arrays.asList(DriveScopes.DRIVE_METADATA_READONLY);

到:

private static final java.util.Collection<String> SCOPES =
    DriveScopes.all();

2) 删除您现有的存储凭据,以便再次获取它们,然后重新执行您的程序:

rm ~/.credentials/drive-java-quickstart/StoredCredential

注意:您需要一个名为 client_secret.json 的 OAuth 客户端 ID 文件,而不是 client_id.json 文件(我认为 - 无论如何这对我有用)。

【讨论】:

    【解决方案2】:

    由于您使用的是 QuickStart 中的确切代码,它可能与范围集有关,它当前设置为 DriveScopes.DRIVE_METADATA_READONLY,如果您在 Choose Auth Scopes 页面中查看它的含义,它会指出

    允许只读访问文件元数据,但不允许任何访问读取或下载文件内容

    您可以查看引用的页面以了解您将确切使用的范围。它最有可能是https://www.googleapis.com/auth/drive,因此请查看DriveScopes 类以获得相同性质的常量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      相关资源
      最近更新 更多