如何使用 Drive SDK 列出域中的所有 Google 文档?
How to list all Google document from the Domain using Drive SDK?
我想列出 google domain.I 中的所有文档,并尝试了 google 文档中提到的内容:
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 驱动器文件??我用过超级管理员,但我无法获取。
你不能 :) 因为 Google 云端硬盘文件所有权逻辑是以用户为中心的。
您只能列出用于调用 API 的用户 "My Drive" 中的文件。
要获取您的 Google Apps 域中的所有文件,您需要:
- 使用您的服务帐户和应用设置 domain-wide delegation of authority。
- 使用目录 API users.list() API 调用来确定 Google Apps 域中的所有用户。
- 作为每个用户,调用 files.list(q='"me" in owners') 以获取该用户拥有的所有文件的列表。
所有这些调用的组合结果将是您的 Google Apps 域中的所有文件。
我想列出 google domain.I 中的所有文档,并尝试了 google 文档中提到的内容: 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 驱动器文件??我用过超级管理员,但我无法获取。
你不能 :) 因为 Google 云端硬盘文件所有权逻辑是以用户为中心的。
您只能列出用于调用 API 的用户 "My Drive" 中的文件。
要获取您的 Google Apps 域中的所有文件,您需要:
- 使用您的服务帐户和应用设置 domain-wide delegation of authority。
- 使用目录 API users.list() API 调用来确定 Google Apps 域中的所有用户。
- 作为每个用户,调用 files.list(q='"me" in owners') 以获取该用户拥有的所有文件的列表。
所有这些调用的组合结果将是您的 Google Apps 域中的所有文件。