问题描述
我正在尝试使用 Google Drive API (v3) 更新文档在 Google 云端硬盘中.
I am trying to use Google Drive API (v3) to make updates to documentsin Google Drive.
我已阅读此迁移指南:Google Drive API v3 迁移
并对其进行编码以创建一个新的空 File(),其中包含我要更新的详细信息然后使用该文件和文件 ID 调用 execute().但我仍然收到错误消息.谁能指出我做错了什么?非常感谢!!
And coded it to make a new empty File() with the details I want to updateand then calling execute() with that and the file ID.But i am still getting an error. Can anyone point out where I am doing wrong?thanks alot!!
错误:
{
"code" : 403,
"errors" : [{
"domain" : "global",
"message" : "The resource body includes fields which are not directly writable.",
"reason" : "fieldNotWritable"
}],
"message" : "The resource body includes fields which are not directly writable."
}
下面的代码片段:
File newFileDetails = new File();
FileList result = service2.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name)")
.execute();
List<File> files = result.getFiles();
if (files == null || files.size() == 0) {
System.out.println("No files found.");
} else {
System.out.println("Files:");
for (File file : files) {
if (file.getName().equals("first_sheet")) {
System.out.printf("%s (%s)
", file.getName(), file.getId());
newFileDetails.setShared(true);
service2.files().update(file.getId(), newFileDetails).execute();
}
}
}
推荐答案
参考 https://developers.google.com/drive/v3/reference/files#resource-representations,您可以看到 shared
不是可写字段.如果你仔细想想,这完全有道理.您可以通过添加新权限来共享文件,您可以通过读取共享属性来检查文件是否已共享.但是说一个文件是共享的,而不是实际共享它,是没有意义的.
Referring to https://developers.google.com/drive/v3/reference/files#resource-representations, you can see that shared
isn't a writable field. If you think about it, this makes perfect sense. You can share a file by adding a new permission, and you can check if a file has been shared by reading the shared property. But saying a file is shared, other than by actually sharing it, makes no sense.
这篇关于无法使用 Drive API v3 更新 Google Drive 文件 - 资源正文包含不可直接写入的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!