1

我正在尝试在 Google Team Drive 中找到一个文件夹,该文件夹具有多个级别的文件夹结构。

这是一个例子:

Team Drive

    - Folder A

       - Folder B

           - Folder C

我想Folder C使用 Team Drive 的文件夹 ID 进行搜索。如果文件夹存在,则返回文件夹 ID Folder C,如果不存在,则在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 才能找到文件夹,或者有没有办法让查询在整个团队云端硬盘中搜索文件夹?

4

0 回答 0