我正在尝试在Google Team Drive中找到一个文件夹,该文件夹的文件夹结构具有多个级别。
这里是一个例子:
Team Drive
- Folder A
- Folder B
- Folder C
我想使用Team Drive的文件夹ID搜索Folder C
。如果该文件夹存在,请返回Folder C
的文件夹ID,如果不存在,请在Folder B
下创建该文件夹。
因此,我有一些正在使用的代码来创建Google Drive API查询。
这是我正在使用的代码段-(Team Drive ID)将是ID:
// Set the drive query...
String driveQuery = "mimeType='application/vnd.google-apps.folder' and '(Team Drive ID)' in parents and name='Folder C' and trashed=false";
try {
result = service.files().list().setQ(driveQuery).setIncludeTeamDriveItems(true).setSupportsTeamDrives(true)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
for (File folder : result.getFiles()) {
System.out.printf("Found folder: %s (%s)\n", folder.getName(), folder.getId());
foundFolder = true;
folderID = folder.getId();
}
if (foundFolder != true) {
// Need to create the folder...
File fileMetadata = new File();
fileMetadata.setName(folderKeyToGet);
fileMetadata.setTeamDriveId(parentFolderID);
fileMetadata.set("supportsTeamDrives", true);
fileMetadata.setMimeType("application/vnd.google-apps.folder");
fileMetadata.setParents(Collections.singletonList(parentFolderID));
try {
newFolder = service.files().create(fileMetadata).setSupportsTeamDrives(true).setFields("id, parents")
.execute();
} catch (IOException e) {
e.printStackTrace();
}
// Send back the folder ID...
folderID = newFolder.getId();
System.out.println("Folder ID: " + newFolder.getId());
}
return folderID;
我将查询设置为:
"mimeType='application/vnd.google-apps.folder' and '(Team Drive ID)' in parents and name='Folder C' and trashed=false"
但似乎没有遍历文件夹结构以找到Folder C
文件夹。
我是否需要拥有Folder B
文件夹ID才能找到该文件夹,还是可以通过查询在整个Team Drive中搜索该文件夹?