I'm trying to search for files in the drive with Java, but I'm not sure how to set the conditions. The example given in the video tutorial is in Python. So, basically here is the method that will retrieve the List of files from the Drive:
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;
}
Now, they mention here that the File.List method accepts the q parameter. How can I do that? When I try to set the parameter with examples like the given in the video where q = "title contains 'fruit'", it does not work. What am I doing wrong? Is the request.queue() used for this?
Thanks
Use setQ
method for Files list request.
https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/Drive.Files.List.html#setQ(java.lang.String)
For examples on how to query for files/folders:
https://developers.google.com/drive/web/search-parameters#examples
I found it. I think the Google Drive SDK documentation needs to be a little less ambiguous.
Files.List request = service.files().list().setQ("mimeType = 'application/vnd.google-apps.folder'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With