Google驱动器对文件的权限不足

时间:2015-04-13 02:41:04

标签: java google-drive-api

我正在尝试使用Java在Google云端硬盘上发布文件夹。我找到并尝试了this code

但我收到如下错误:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "location" : "file.permissions",
    "locationType" : "other",
    "message" : "Insufficient permissions for this file",
    "reason" : "forbidden"
  } ],
  "message" : "Insufficient permissions for this file"
}

我的访问类型处于脱机状态,范围为https://www.googleapis.com/auth/drive,我的客户端是一个Web应用程序。

添加我的代码:

 private static String CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxx";
  private static String CLIENT_SECRET = "xxxxxxxxxxxx";
  public String auth_code = "xxxxxxxxxxxxxxxxxxxxxxxxx";
  public String accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxx";

  Credential credentials = new GoogleCredential.Builder().setJsonFactory(jsonFactory)
                         .setTransport(httpTransport).setClientSecrets(CLIENT_ID,CLIENT_SECRET).build();

  credentials.setAccessToken(accessToken);
  credentials.setRefreshToken(refreshToken);

  Drive service = new Drive.Builder(httpTransport, jsonFactory,   credential).setApplicationName("reports").build();

  Permission permission = new Permission();
  permission.setValue("");
  permission.setType("anyone");
  permission.setRole("reader");
  service.permissions().insert(fileID, permission).execute();

最后一行的错误或错误

0 个答案:

没有答案