Prabhat Subedi Prabhat Subedi - 3 months ago 11
Java Question

Google Drive SDK API does not lists the file uploaded by Google Drive in java

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 ...

Answer

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.