Reputation: 9289
Below is the code I am using to find list of files containing Volunteers.
private static List<File> retrieveAllFiles(Drive service) throws IOException {
List<File> result = new ArrayList<File>();
Files.List request = service.files().list().setQ("Volunteers");
System.out.println("Request size:" + request.size());
do {
try {
FileList files = request.execute();
System.out.println("Request files size:" + files.size());
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;
}
On execution it returns
[s~sakshumweb-hrd/3.368839385999923807].<stdout>: An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 OK
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "q",
"locationType" : "parameter",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
What is wrong with it.
Upvotes: 0
Views: 2910
Reputation: 2987
I'm not really sure about what you are trying to search when you want to "find list of files containing Volunteers", but you should specify from which resource of the file you want to search your query.
For example, if you want to search for files containing "Volunteers" in the title, your code should be service.files().list().setQ("title contains 'Volunteers'");
or if you want to search both title and contents of the file to see if they contain "Volunteers", your code should look like service.files().list().setQ("fullText contains 'Volunteers'");
Please take closer look at search parameters documentation. It will give you better sense of how to search for files.
Upvotes: 3