2
votes

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;
        }
2
Please check the edit on my question and my apology for jumping to conclusions sometimes its not the standard answer. - DaImTo
The simple answer is often the best answer. I do appreciate you taking the time to respond and doing some of your own investigation. - Cheticamp
Your comment to the other question intrigued me enough to go and play with it. I am always up for Google bug hunting not many people find legitimate bugs this is an accomplishment. :) - DaImTo
Lucky me.....;) - Cheticamp

2 Answers

2
votes

Major edit of answer:

I think you should report this as an bug to Google. I have been playing with it and I cant get appProperties to return as part of a file.list its like the file resource doesn't contain that field so you get an error from the search. This is true even when I have fields set to * which should return all the fields of a file resource.

When you report it send them your examples apps-api-issues link this question as well. Link your issue request back here and I will see if I can find someone on the Google Drive to ping about it.

0
votes

Exponential backoff only applies if the error is transient. This only happens occasionally, eg. when there is a data centre outage.

Many 500 errors are bugs in GDrive where an invalid (or occasionally, even valid) request is being dealt with incorrectly. I suggest you use https://developers.google.com/drive/v3/reference/files/list#try-it to ensure that your query string is correctly formed, quoted, etc.