How to list all Google document from the Domain us

2020-07-27 03:33发布

I want to list all the document from google domain.I have tried the as per mention in google documentation : https://developers.google.com/drive/v2/reference/files/list#examples

I have created service with as follow :

 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();

When i am executing this request as follows :

 FileList files = request.execute();

I got only 'userEmail' (Provided while creating service) files.

How i can get all domain google drive files ?? i have used super admin but i couldn't get.

2条回答
家丑人穷心不美
2楼-- · 2020-07-27 03:52

You can't :) because Google Drive file ownership logic is user-centric.

You can only list files that are in the "My Drive" of the user used to call APIs.

查看更多
We Are One
3楼-- · 2020-07-27 03:55

To get all files in your Google Apps domain you would need to:

  1. Setup domain-wide delegation of authority with your Service Account and Apps.
  2. Use the Directory API users.list() API call to determine all users in the Google Apps domain.
  3. As each user, call files.list(q='"me" in owners') to get a list of all files the user owns.

The combined results of all these calls would be all files in your Google Apps domain.

查看更多
登录 后发表回答