![](/img/trans.png)
[英]Creating a okhttp3 request body to create a folder in google drive
[英]Error while creating Google Drive folder into another folder
我需要将GDrive
文件夹创建到另一个GDrive
文件夹中。
有代码:
private static String createDriveFolder(String folderName, String mainFolder, Drive service) throws IOException {
File fileMetadata = new File();
fileMetadata.setName(folderName);
fileMetadata.setParents(Collections.singletonList(mainFolder));
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = service.files().create(fileMetadata)
.setFields("id, parent")
.execute();
System.out.println("Folder ID: " + file.getId());
return file.getId();
}
我得到这个错误...
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "fields",
"locationType" : "parameter",
"message" : "Invalid field selection parent",
"reason" : "invalidParameter"
} ],
"message" : "Invalid field selection parent"
}
请帮我...
这个改装怎么样? 我认为从错误消息来看,问题的原因是由于fields
的值。
.setFields("id, parent")
.setFields("id, parents")
请将parent
修改为parents
。 在 Google Drive,在当前阶段,一个文件和文件夹有多个父级。 所以用了parents
。 但是我们可以看到下面的公告。 参考
从 2020 年 9 月 30 日开始,将无法再将一个项目放置在多个文件夹中; 每个项目将只有一个位置。 在新的 model 中,可以使用快捷方式来组织多个层次结构中的内容。 Drive 文件夹结构和共享模型的这种简化将导致某些 Google Drive API 端点的行为方式发生变化。
parents
是否会更改为parent
。 因此,关于此,我想确认 2020 年 9 月 30 日之后驱动器 API 的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.