Swap L
Swap L

Reputation: 718

How to list all Google document from the Domain using Drive SDK?

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.

Upvotes: 3

Views: 1089

Answers (2)

Jay Lee
Jay Lee

Reputation: 13528

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.

Upvotes: 8

aqquadro
aqquadro

Reputation: 1027

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.

Upvotes: 1

Related Questions