1
votes

I want to access complete file list of Google Drive folder (this list should contain files not created by me too)

Issue I am facing: with Drive SDK, only two types of scopes seems to be permissible- FILE_SCOPE and APP_FOLDER_SCOPE. They can only fetch files which are created by the application.

While changing to a more open scope- https://www.googleapis.com/auth/drive.readonly, I am getting statusCode=INTERNAL_ERROR, resolution=null while trying to connect GoogleApiClient.

Is it possible to have complete (read-only) access to Google Drive programmatically through Drive SDK?

Any suggestions or pointers for further R&D are welcome.

3
My Sources: [Listing of Drive scopes] developers.google.com/drive/v2/web/scopes#google_drive_scopes [SO reply hinting limitation of Drive SDK]stackoverflow.com/questions/31438296/… - Apporve Chandra
GDAA only supports drive.file scope. If you want to see all files you'll need to use the REST API. - pinoyyid

3 Answers

1
votes

Using the REST API you should use something like :

List<String> fileInfo = new ArrayList<String>();
        FileList result = mService.files().list()
             .setPageSize(10)
             .setFields("nextPageToken, items(id, name)")
             .execute();
        List<File> files = result.getFiles();
        if (files != null) {
            for (File file : files) {
                fileInfo.add(String.format("%s (%s)\n",
                        file.getName(), file.getId()));
            }
        }

To list all files.Go there for more infos : https://developers.google.com/drive/v3/web/quickstart/android

0
votes

You should activate Drive API from the console with following steps .

  1. Go to the Google API Console.
  2. Select a project.
  3. In the sidebar on the left, expand APIs & auth and select APIs.
  4. In the displayed list of available APIs, click the link for the Drive API and click Enable API.
0
votes

You have to set page Token Every time in while, for listing all files in G drive :

private static List<File> getAllFilesGdrive(Drive service) throws IOException {
    List<File> result = new ArrayList<File>();
    Files.List request = service.files().list();

    do {
      try {
        FileList files = request.execute();

        result.addAll(files.getFiles());
        request.setPageToken(files.getNextPageToken());
      } catch (IOException e) {
        System.out.println("An error occurred: " + e);
        request.setPageToken(null);
      }
    } while (request.getPageToken() != null &&
             request.getPageToken().length() > 0);

    return result;
  }