java - 将 Google Drive 文件夹创建到另一个文件夹时出错
问题描述
我需要将文件夹创建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 日开始,将无法再将一个项目放置在多个文件夹中;每个项目将只有一个位置。在新模型中,可以使用快捷方式来组织多个层次结构中的内容。Drive 文件夹结构和共享模型的这种简化将导致某些 Google Drive API 端点的行为方式发生变化。
- 我不确定是否
parents
会更改为parent
. 因此,关于这个,我想确认 2020 年 9 月 30 日之后 Drive API 的更改。
- 我不确定是否
参考:
推荐阅读
- javascript - 注销时保留动态添加的 DOM 元素
- node.js - 开发服务器返回响应错误码:500 - running React Native project
- ios - 显示地图的 Sygic 问题
- android - 如何更新自定义 PrimaryDrawerItem 中的视图?
- angular - 在函数中使用 subscribe 测试 Observable
- angular - 如何处理以角度反应形式的对象数组形式出现的响应
- c# - 如何从资源中提取二进制文件?
- java - java 获取 Active Directory RootDSE
- lua - 避免在 Lua 中使用具有特定回调机制的全局变量
- java - 不能在单独的类中添加到根目录?