gpt4 book ai didi

java - Google Drive.Permissions.update 开始在 "500 OK"异常中失败

转载 作者:行者123 更新时间:2023-12-01 13:22:04 25 4
gpt4 key购买 nike

我使用了以下类型的 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();

关于java - Google Drive.Permissions.update 开始在 "500 OK"异常中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21964951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com