3

I am creating an application which can insert files into Google Drive and lists it. I am using Google Drive SDK v2 API. But my problem is it is not listing files which is not uploaded through my application. If I upload directly from Google drive it is not listed in my application.

Here is the method to list the file:

private static List<File> retrieveAllFiles(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.getItems());
            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;
      }

and I am iterating files like this :

List<File> files = retrieveAllFiles(service);
        for(File f : files) {
            System.out.println("File Name : "+f.getOriginalFilename();
        }

Can anyone help me please ? Thanks in advance ...

Jerome
  • 2,104
  • 1
  • 17
  • 31
Narayan Subedi
  • 1,343
  • 2
  • 20
  • 46

1 Answers1

2

I think you are using the wrong oauth scope, probably https://www.googleapis.com/auth/drive.file which restrict your app's access to file created or opened by your app, when you should use https://www.googleapis.com/auth/drive which gives full control to your app.

Jerome
  • 2,104
  • 1
  • 17
  • 31
  • 1
    @PrabhatSubedi: Did Google change anything lately...changing the scope as suggested still only lists files created by my app. http://stackoverflow.com/questions/27759077/drive-sdk-not-listing-all-my-files – user_78361084 Jan 06 '15 at 03:44
  • @llamawithabowlcut Currently not working in Google Drive... Better look for documentation and version of SDK. – Narayan Subedi Jan 06 '15 at 05:19