我正在使用Google Drive v3,并且试图获取与以下类别相关的所有文件:
我想一次获得所有这些文件。
第一类文件可以通过以下子查询获取:
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 Spreadsheet文件。 我试图分别对这两个文件类别执行查询,它们工作正常:
'<parentId>' in parents and (mimeType = 'application/vnd.google-apps.spreadsheet')
返回所有Google Spreadsheets
和
'<parentId>' in parents and (not mimeType contains 'application/vnd.google-apps.')
返回所有非Google云端硬盘格式。
`
作为实验,我检查了另一种情况(简化了一点):
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。
请帮助。
答案 0 :(得分:0)
除了Google Spreadsheet之外,您想检索所有与Google相关的文件。
- 不是Google文档的文件(MIME类型不是从“ application / vnd.google-apps”开始的。),例如“ text / plain”,“ image / bmp”等。
- Google电子表格(MIME类型为“ application / vnd.google-apps.spreadsheet”)
您想通过一个搜索查询的单个请求来实现。
如果我的理解正确,那么该查询如何?请认为这只是几个答案之一。
根据您的情况和经过测试的示例查询,该查询如何忽略除application/vnd.google-apps.spreadsheet
以外的所有Google文档的mimeType?可以在here上看到与Google相关的文件的所有mimeType。
'<parentId>' in parents and (mimeType!='application/vnd.google-apps.audio' and mimeType!='application/vnd.google-apps.document' and mimeType!='application/vnd.google-apps.drawing' and mimeType!='application/vnd.google-apps.file' and mimeType!='application/vnd.google-apps.folder' and mimeType!='application/vnd.google-apps.form' and mimeType!='application/vnd.google-apps.fusiontable' and mimeType!='application/vnd.google-apps.map' and mimeType!='application/vnd.google-apps.photo' and mimeType!='application/vnd.google-apps.presentation' and mimeType!='application/vnd.google-apps.script' and mimeType!='application/vnd.google-apps.site' and mimeType!='application/vnd.google-apps.unknown' and mimeType!='application/vnd.google-apps.video' and mimeType!='application/vnd.google-apps.drive-sdk')
或
'<parentId>' in parents and not (mimeType='application/vnd.google-apps.audio' or mimeType='application/vnd.google-apps.document' or mimeType='application/vnd.google-apps.drawing' or mimeType='application/vnd.google-apps.file' or mimeType='application/vnd.google-apps.folder' or mimeType='application/vnd.google-apps.form' or mimeType='application/vnd.google-apps.fusiontable' or mimeType='application/vnd.google-apps.map' or mimeType='application/vnd.google-apps.photo' or mimeType='application/vnd.google-apps.presentation' or mimeType='application/vnd.google-apps.script' or mimeType='application/vnd.google-apps.site' or mimeType='application/vnd.google-apps.unknown' or mimeType='application/vnd.google-apps.video' or mimeType='application/vnd.google-apps.drive-sdk')
或
'<parentId>' in parents and not (mimeType='application/vnd.google-apps.audio' or mimeType contains 'application/vnd.google-apps.d' or mimeType contains 'application/vnd.google-apps.f' or mimeType contains 'application/vnd.google-apps.m' or mimeType contains 'application/vnd.google-apps.p' or mimeType='application/vnd.google-apps.script' or mimeType='application/vnd.google-apps.site' or mimeType='application/vnd.google-apps.unknown' or mimeType='application/vnd.google-apps.video')
pageToken
。此时,需要完成多个请求。请注意这一点。如果这不是您想要的方向,我深表歉意。