我使用了以下Java代码(在AppEngine中)来转移Google云端硬盘中文件的所有权。突然,此操作因服务器“ 500 OK”错误而开始失败。发生了什么变化或这可能是什么原因?
// first add new owner as "writer"
Permission newPermission= new Permission();
newPermission.setValue(newOwnerEmail);
newPermission.setType("user");
newPermission.setRole("writer");
Insert insert = service.permissions().insert(fileId, newPermission);
newPermission = insert.execute();
// then transfer ownsership
newPermission.setRole("owner");
newPermission.setValue(newOwnerEmail);
Update update = drive.permissions().update(fileId, newPermission.getId(), newPermission);
update.setTransferOwnership(true);
update.execute();
异常消息就是这样,它并不能说明太多...?
500 OK
{
"code" : 500,
"message" : null
}
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:312)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1045)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
etc...
最佳答案
确定,我找到了这些修复程序的解决方案:
1)将Drive API库更新为1.17.0
2)准备所有权转让时,立即将新的所有者许可角色设置为“所有者”。在早期的API版本中,它必须首先是“ writer”。
这是更正后的代码段:
// first add new permission as "owner"
Permission newPermission= new Permission();
newPermission.setValue(newOwnerEmail);
newPermission.setType("user");
newPermission.setRole("owner");
Insert insert = service.permissions().insert(fileId, newPermission);
newPermission = insert.execute();
// then transfer ownsership
newPermission.setValue(newOwnerEmail);
Update update = drive.permissions().update(fileId, newPermission.getId(), newPermission);
update.setTransferOwnership(true);
update.execute();