如何获取Google共享驱动器根ID

时间:2019-08-16 09:35:12

标签: java google-drive-api

我有与我共享的云端硬盘ID。 我想找到共享驱动器的根ID。

my Drive: root

shared With me : sharedWithMe

1 个答案:

答案 0 :(得分:1)

您甚至可以尝试使用Postman或SOAP UI来获取此官方链接中提到的详细信息:

https://developers.google.com/drive/api/v2/reference/files/get#try-it

在邮递员/肥皂用户界面中击中GET https://www.googleapis.com/drive/v2/files/root会产生JSON响应,其中将提及您的根。

注意:在以上请求中,root是您的根文件夹的别名。您应该得到一个JSON响应,其中您应该具有根文件夹的“ id”。

如果您想了解文件夹结构,请尝试以下操作,否则请尝试执行上述步骤。

File fileMetadata = new File();
fileMetadata.setName("Invoices");
fileMetadata.setMimeType("application/vnd.google-apps.folder");

File file = driveService.files().create(fileMetadata)
    .setFields("id")
    .execute();
System.out.println("Folder ID: " + file.getId());
  

在Drive API中,文件夹本质上是一个文件,其中的一个由   特殊文件夹MIME类型为application / vnd.google-apps.folder。您   可以通过插入具有此MIME类型的文件和一个   文件夹标题。设置文件夹标题时,请勿包含扩展名。

参考:https://developers.google.com/drive/api/v3/folder