0
votes

I have below piece of code to list out all available folders using Drive API's. But after 3000 folders it error out as '500 Internal Error'. How to find which folder and why this error is coming based on the NextPageToken?

Note: It was working properly in last week and from today we started seeing this issue.

Note: Even retry does not work. I have changed the MaxResults value to 1 but even though it fails.

FilesResource.ListRequest list = _DriveService.Files.List();
                    list.Q = "mimeType = 'application/vnd.google-apps.folder' and trashed = false";
                    list.MaxResults = 1000;
                    FileList folders = null;
                    do
                    {
                        folders = list.Fetch<FileList>();
                        foreach (File folder in folders.Items)
                        {
                        retColl.Add(folder.Id, folder);
                        }
                        list.PageToken = folders.NextPageToken;
                    } while (!string.IsNullOrEmpty(list.PageToken));
1
Can you clarify, does it always fail after exactly 3000? - pinoyyid
It is failing for me to read exact 3021th folder. I am able to fetch 3020 folders, but with next page token and with query MaxResult=1, I am getting '500 Internal Server Error'. - Jeevan
So next is to figure if the issue is the number 3021, or the folder. Can you create 10 more folders and see if it fails in the same place. - pinoyyid
I have only "Read" access to this Google Drive by using only "Google Admin APIs". Also the same issue is observed for another user where I am able to collect 5041 folders. I am suspecting any kind of special folder(or corrupted one) is shared among this users for which Google Server is failing to read. - Jeevan

1 Answers

0
votes

In general, you can get ERROR 500 randomly, meaning your request can't be satisfied for various (hard to qualify) reasons. I remember seeing a YouTube (Ali Afshar or Steven Bazyl) discussing handling of this. Your code SHOULD be prepared to handle this by re-try after RANDOM amount of time.