我想列出来自谷歌域的所有文档。我已经尝试过谷歌文档中提到的: https://developers.google.com/drive/v2/reference/files/list#examples
我创建了如下服务:
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Arrays.asList(DriveScopes.DRIVE))
.setServiceAccountUser(userEmail)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
Files.List request = service.files().list();
当我按如下方式执行此请求时:
FileList files = request.execute();
我只有“userEmail
”(创建服务时提供)文件。
如何获取所有域 google 驱动器文件?我使用了 super 管理员,但我无法获得。
最佳答案
要获取您的 Google Apps 域中的所有文件,您需要:
- 设置 domain-wide delegation of authority使用您的服务帐号和应用。
- 使用目录 API users.list()用于确定 Google Apps 域中的所有用户的 API 调用。
- 作为每位用户,请调用 files.list(q='"me" in owners')获取用户拥有的所有文件的列表。
所有这些调用的组合结果将是您的 Google Apps 域中的所有文件。
关于java - 如何使用 Drive SDK 列出域中的所有 Google 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29483347/