【发布时间】:2020-01-21 17:29:11
【问题描述】:
我正在使用 Google Drive v3,我正在尝试获取与以下类别相关的所有文件:
- 不是 Google 文档的文件(mime 类型不是从“application/vnd.google-apps”开始),例如“text/plain”、“image/bmp”等。
- Google 电子表格(mime 类型为“application/vnd.google-apps.spreadsheet”)
我想通过单个请求获取所有这些文件。
可以通过以下子查询获取第一类文件:
not mimeType contains 'application/vnd.google-apps.'
第二类子查询:mimeType = 'application/vnd.google-apps.spreadsheet'
因此,我将这些部分与 or 运算符结合起来,然后查询父文件夹 ID:
'<parentId>' in parents and (mimeType = 'application/vnd.google-apps.spreadsheet' or not mimeType contains 'application/vnd.google-apps.')
但它不起作用。它仅返回 Google 电子表格文件。 我尝试分别对两个文件类别执行查询,它们工作正常:
'<parentId>' in parents and (mimeType = 'application/vnd.google-apps.spreadsheet') 返回所有 Google 电子表格
和
'<parentId>' in parents and (not mimeType contains 'application/vnd.google-apps.') 返回所有非 Google Drive 格式。
`
作为实验,我检查了另一个案例(有点简化):
-
mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType = 'text/plain'- 返回电子表格+文本,正确 -
mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType contains 'text/plain'- 仅返回电子表格,不正确 -
mimeType = 'application/vnd.google-apps.spreadsheet' or not mimeType = 'text/plain'- 仅返回电子表格,不正确(我的文件夹中也有图片) -
mimeType contains 'text/plain'- 返回文本,正确
我的部分文件请求代码(当然,已替换 parentId):
Drive.Files.List filesRequest = service
.files()
.list()
.setFields("files(id, name)")
.setQ("'<parentId>' in parents " +
"and (mimeType = 'application/vnd.google-apps.spreadsheet' " +
"or not mimeType contains 'application/vnd.google-apps.')");
FileList result = filesRequest.execute();
List<File> files = result.getFiles();
使用的依赖版本:google-api-services-drive 从 v3-rev162-1.23.0 到 v3-rev173-1.25.0,JDK 1.8.0-91。
请帮忙。
【问题讨论】:
标签: java google-drive-api