【问题标题】:Updating file permission to "owner" fails with 500 internal error将文件权限更新为“所有者”失败并出现 500 内部错误
【发布时间】:2014-04-05 00:23:38
【问题描述】:

对于我们的域,需要将特定文件夹中的文件从一个用户传输到管理员帐户。管理员帐户对所有文件都具有“作者”角色。两个用户在同一个域中。

我使用域范围的委托作为授权方法。

将管理员帐户的权限从“writer”更新为“owner”时,程序返回 500 Internal Error。任何帮助将不胜感激。谢谢!

public static Drive getDriveService(String userEmail) throws GeneralSecurityException,IOException, URISyntaxException {
  HttpTransport httpTransport = new NetHttpTransport();
  JacksonFactory jsonFactory = new JacksonFactory();
  Collection<String> scope = new ArrayList<String>();
  scope.add(DriveScopes.DRIVE);

  GoogleCredential credential = new GoogleCredential.Builder()
      .setTransport(httpTransport)
      .setJsonFactory(jsonFactory)
      .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
      .setServiceAccountScopes(scope)
      .setServiceAccountUser(userEmail)
      .setServiceAccountPrivateKeyFromP12File(
          new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
      .build();

  Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
      .setHttpRequestInitializer(credential).build();
  return service;
}

public static void main(String[] args) {
    try {
        Drive userDriveService = getDriveService(ADMIN_ACCT_EMAIL);
        ChildList list = userDriveService.children().list(folderId).setQ("not '" + ADMIN_ACCT_EMAIL + "' in owners").execute();
        java.util.List<ChildReference> children = list.getItems();
                //Simplified for testing
        ChildReference child = children.get(0);
        String fileId = child.getId();
        String permId = userDriveService.permissions().getIdForEmail(ADMIN_ACCT_EMAIL).execute().getId();
        Permission perm = userDriveService.permissions().get(fileId, permId).execute();
        perm.setRole("owner");
        userDriveService.permissions().update(fileId, permId, perm).setTransferOwnership(true).execute();
    } catch (GeneralSecurityException | IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

  • 已解决问题:必须获取文件的原始所有者,使用原始所有者的电子邮件获取驱动服务,然后使用该驱动服务更新文件权限。谢谢。

标签: google-drive-api


【解决方案1】:

意识到我应该使用车主的电子邮件来获取驱动服务。这在更改那一行后起作用。谢谢。

    Drive userDriveService = getDriveService(ORIGINAL_OWNER_EMAIL);

【讨论】:

    猜你喜欢
    • 2019-08-31
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多