我正在请求在Team Drive中查找属于某个客户端的所有文件。
基于答案here,这是代码:
function listFiles (){
var client = 'client'
var teamDriveId = 'id';
var pageToken;
var folders = Drive.Files.list({
corpora: 'teamDrive',
supportsTeamDrives: true,
teamDriveId: teamDriveId,
includeTeamDriveItems: true,
q: "title = 'data'"
});
if (folders.items.length !== 1) {
Logger.log('There is a problem.');
return;
}
var query = "name contains '" + client + // this client only
"' and trashed = false and " + // not in trash
"not mimeType = 'application/vnd.google-apps.folder'"; // no folders
Logger.log(query)
var files, pageToken;
do {
files = Drive.Files.list({
q: query,
maxResults: 100,
pageToken: pageToken,
// required for team drive queries
corpora: 'teamDrive',
supportsTeamDrives: true,
teamDriveId: teamDriveId,
includeTeamDriveItems: true
});
if (files.items && files.items.length > 0) {
for (var i = 0; i < files.items.length; i++) {
var file = files.items[i];
Logger.log('%s (ID: %s) (Modified: %s)', file.title, file.id, file.modifiedDate);
}
}
} else {
Logger.log('No files found.');
}
pageToken = files.nextPageToken;
} while (pageToken);
}
如果我不包括查询的"name contains '" + client'"
部分,它可以正常工作。如果我这样做,它将返回一个错误,指出:“无效查询”。
看着docs,我不明白我的语法与那里指定的语法有何不同。
我已经尝试过以下几种方法:
"name contains 'client' and trashed = false and not mimeType = 'application/vnd.google-apps.folder'"
"trashed = false and not mimeType = 'application/vnd.google-apps.folder' and name contains 'client'"
有什么办法解决这个问题吗?