java google api电子表格:请求的认证范围不足。

时间:2017-07-12 10:31:17

标签: java google-app-engine java-8 google-cloud-platform

我在java中为google-api设置了一个电子表格处理程序:

private GoogleCredential getCredentials(InputStream secret) throws GeneralSecurityException,
        IOException, URISyntaxException {
    GoogleCredential credential;

    if ( secret == null ) {
        credential = GoogleCredential
                .getApplicationDefault()
                .createScoped(SheetsScopes.all());
    } else {
        credential = GoogleCredential
                .fromStream(secret)
                .createScoped(SheetsScopes.all());
    }

    return credential;
}

  public static java.util.Set<String> all() {
    java.util.Set<String> set = new java.util.HashSet<String>();
    set.add(DRIVE);
    set.add(DRIVE_FILE);
    set.add(DRIVE_READONLY);
    set.add(SPREADSHEETS);
    set.add(SPREADSHEETS_READONLY);
    return java.util.Collections.unmodifiableSet(set);
  }

我尝试在appengine(java8)上运行此代码,当我尝试从电子表格中读取时出现异常(我的appengine email是该电子表格的编辑器)

com.google.apphosting.runtime.jetty9.JettyLogger warn: /
java.lang.RuntimeException: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Request had insufficient authentication scopes.",
    "reason" : "forbidden"
  } ],
  "message" : "Request had insufficient authentication scopes.",
  "status" : "PERMISSION_DENIED"
}

我该如何调试或修复此问题?

0 个答案:

没有答案