Update: This issue appears to have been resolved. See the bug tracker report for details.
I am having some difficulty getting a file listing request through the Drive REST API (v3) accomplished without an
internal server error (error code 500.) I am trying to use the name and appProperties keys with a call to
files().list() in the search criteria with name and createdTime for the sort order. (This is "case 1" in
the code below.) The syntax I am using is documented here.
In an attempt to isolate the problem, I have taken the Google Drive API > REST Android Quickstart project
found here and made some modifications to
the getDataFromApi method as shown in the code block below.
There are six test cases using various combinations of search criteria and sort order fields. Some queries succeed while others fail with server code 500 and one times out. These results are consistent on an emulator running Android 7.0 with API 24. My issue originated with an earlier release.
I am most interested in getting a solution to case 1 and offer the other cases as my attempt to figure out what was going wrong. I would appreciate any assistance or ideas on what I might be doing wrong or what else may be happening.
private List<String> getDataFromApi() throws IOException {
// Get a list of up to 10 files.
List<String> fileInfo = new ArrayList<String>();
/* Case 1: Crashes with following error:
500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError"
}],
"message" : "Internal Error"
} */
String query = "name contains 'Test' and not appProperties has {key='X' and value='Y'}";
String orderBy = "name, createdTime";
// Case 2: Succeeds and lists files.
// Like case 1, but "createdTime is dropped in sort order.
// String query = "name contains 'Test' and not appProperties has {key='X' and value='Y'}";
// String orderBy = "name";
// Case 3: Succeeds and lists files.
// Like case 1, but appProperties criteria is dropped.
// String query = "name contains 'Test'";
// String orderBy = "name, createdTime";
// Case 4: Times out.
// Like case 1, but the name criteria is dropped.
// String query = "not appProperties has {key='X' and value='Y'}";
// String orderBy = "name, createdTime";
// Case 5: Errors out like case 1.
// Like case 4, but the selection query is inverted.
// String query = "appProperties has {key='X' and value='Y'}";
// String orderBy = "name, createdTime";
// Case 6: Succeeds and lists files.
// Like case 4, but name is dropped in sort order.
// final String query = "not appProperties has {key='X' and value='Y'}";
// final String orderBy = "createdTime";
FileList result = mService.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name)")
// following was added
.setOrderBy(orderBy)
.setQ(query)
// end added code
.execute();
List<File> files = result.getFiles();
if (files != null) {
for (File file : files) {
fileInfo.add(String.format("%s (%s)\n",
file.getName(), file.getId()));
}
}
return fileInfo;
}