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 ...
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 usehttps://www.googleapis.com/auth/drive
which gives full control to your app.I built the function we were all really looking for. The following lists all the files and folders inside a google drive folder. You can specify if you want all the files in the directory OR just the files that the service owns inside the directory. Weather you want the ids only, or if you want the file names only or if you want both.
Library_GoogleDriveFileList: