转移文件的所有权失败 - 即使是超级管理员(Google Drive API,Java) [英] Transfer ownership of a file fails - even as Super Administrator (Google Drive API, Java)

查看:362
本文介绍了转移文件的所有权失败 - 即使是超级管理员(Google Drive API,Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将文件的所有权转让给超级管理员。代码的基本部分如下所示。如果我转让我拥有的文档的所有权,则相同的代码有效。但在这种情况下,原始拥有者是同一个域中的另一个用户。 我知道在管理面板中存在一个从一个用户到另一个文件的所有权,但这对于来自多个所有者的多个文件/文件夹需要以编程方式进行转移。 [/编辑]



所以简单的情况就是:


  1. user@domain.com 拥有文件

  2. 所有权需要转移到 admin@domain.com (超级管理员)。代码在Java Servlet中的AppEngine中运行。超级管理员使用OAuth进行身份验证。

然而,它总是在 update.execute(); 行中引发(500 OK) $ c>(最后显示)。
即使是超级管理员也无法执行此操作?



感谢您提供任何提示!

 尝试{
Drive service = getDriveService();
权限newPerm = new Permission();
newPerm.setValue(admin@domain.com);
newPerm.setType(user);
newPerm.setRole(writer);
newPerm = service.permissions()。insert(fileId,newPerm).execute();
newPerm.setRole(owner);
更新update = service.permissions()。update(fileId,newPerm.getId(),newPerm);
update.setTransferOwnership(true);
update.execute();
} catch(IOException e){
e.printStackTrace();
log.severe(e.getMessage());
}

抛出的异常看起来像:

  SEVERE:500 OK 
{
code:500,
errors:[{
domain :全局,
消息:内部错误,
原因:internalError
}],
消息:内部错误


解决方案

。感谢@ZigMandel的模仿提示!现在我仔细地关注此域名范围授权。并使用使用服务帐户 - 键创建的 GoogleCredential 。例如,凭借此凭据,我可以模拟Drive API操作,例如添加权限并将所有权转让给管理员。

仍然存在的问题是,使用当前的Drive API,无法以编程方式确定模拟凭证创建所需的所有者电子邮件地址。现在我需要为此找到解决方法。无论如何,基本的想法现在起作用。谢谢!

I am trying to transfer ownership of files to Super Administrator. The essential part of the code is shown below. The same code works if I transfer ownership of a document that I own. But in this case the original owner is another user in the same domain. [EDIT] I know there is a "transfer-ownership-of-files-from-1-user-to-another" in admin panel, but this is needed for a case when multiple files/folders, from multiple owners needs to be transferred programmatically. [/EDIT]

So the simple scenario is:

  1. user@domain.com owns a file
  2. the ownership needs to be transferred to the admin@domain.com (Super Administrator). The code is running in AppEngine in Java Servlet. And the Super Administrator is authenticated with OAuth.

However it throws (500 OK) exception always in line update.execute(); (showed in the end). Is this operation impossible even for a Super Admin?

Thanks for any tips!

try {
   Drive service = getDriveService();
   Permission newPerm = new Permission();
   newPerm.setValue("admin@domain.com");
   newPerm.setType("user");
   newPerm.setRole("writer");
   newPerm = service.permissions().insert(fileId, newPerm).execute();
   newPerm.setRole("owner");
   Update update = service.permissions().update(fileId, newPerm.getId(), newPerm);
   update.setTransferOwnership(true);
   update.execute(); 
} catch (IOException e) {
   e.printStackTrace();
   log.severe(e.getMessage());
}

The exception thrown looks like:

SEVERE: 500 OK
{
  "code" : 500,
  "errors" : [ {
    "domain" : "global",
    "message" : "Internal Error",
    "reason" : "internalError"
  } ],
  "message" : "Internal Error"
}

解决方案

I finally got this working at least partly. Thanks @ZigMandel for the "impersonation" hint! Now I followed this Domain-wide Delegation of Authority carefully. And used the GoogleCredential created using "Service account"-key. With this credential I can impersonate the Drive API operations like adding permissions and transferring ownership to Admin, for example.

The problem that still remains is that with current Drive API it is impossible to programmatically determine the owner email address, which is needed for impersonated credential creation. Now I need to find a workaround for this. Anyway the fundamental idea works now. Thanks!

这篇关于转移文件的所有权失败 - 即使是超级管理员(Google Drive API,Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆