0

I'm developing a web app in MVC .Net (VS 2019 + Google Drive Api v3). We are using a service account consuming a shared folder from a simple google account. We need to create a folder for each task of our students. We have 2000 students and they have average of 10 tasks per month. So We will have a lot of folders in our Google drive. Because of that I decided to make some tests with a console application and realized some errors after creating multiple folders. Someone know if Google Drive Api has a kind of limit on creation multiple folders? Below is a console application to prove that with a print image.

namespace DriveQuickstart
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };            
            ServiceAccountCredential credential;                                    
            using (var stream =
                            new FileStream("key.json", FileMode.Open, FileAccess.Read))
            {                            
                credential = GoogleCredential.FromStream(stream)
                                     .CreateScoped(Scopes)
                                     .UnderlyingCredential as ServiceAccountCredential;                
            }
            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Test App",
            });
            Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
            for (int i = 0; i < 50; i++)
            {
                body.Name = "Test_" + Guid.NewGuid().ToString();
                body.Description = "Created by me!";
                body.MimeType = "application/vnd.google-apps.folder";
                body.Parents = new List<string> { "1hLsDTub8bhlVS2ax34P8wGx5RsD0n8MA" };
                try
                {
                    service.Files.Create(body).Execute();
                    Console.WriteLine("Folder " + (i+1).ToString() + " created.");
                }
                catch (Exception e)
                {                    
                    Console.WriteLine("Error = " + e.InnerException.Message);
                }
            }                     
        }
    }
}

The inner exception Error: "Unable to read data from transport connection. It was forced to cancel by remote server".

Print2

  • you need to debug the inner exception we cant tell you whats going on with just that single message. However i would bet you are hitting a quota limit. – Linda Lawton - DaImTo May 29 '20 at 08:21
  • There are quotas for maximum number of requests per day and the maximum number of requests per 100s, (see [here](https://stackoverflow.com/a/10313416/11599789)). You are more liekly to hit the second ones. – ziganotschka May 29 '20 at 08:26
  • @DaImTo Thank you for answering! I have edited the post with inner exception message. I realized that I'm not hitting the quota because I run the console (first run of the day) now and create only 17 folders and the error occurs according to print2 image attached. – Rogerio Potenza May 29 '20 at 10:17
  • @ziganotschka Thanks! My concerns about that is the limit of folder creation inside another folder shared with one simple google account working with service account. The quota limit we can deal with it. – Rogerio Potenza May 29 '20 at 10:20
  • There shouldn't be any specific limit about creating about how many files you can create inside the same folder, neither a specific limit for service accounts. However the `per 100 seconds` quota are sometimes calculated for a shorter period. I recommend you to either implement some waiting time between two requests or use [batch requests](https://developers.google.com/drive/api/v3/batch) – ziganotschka May 29 '20 at 11:04
  • @RogerioPotenza are you going to tell us what the inner exception says? – Linda Lawton - DaImTo May 29 '20 at 11:55
  • @ziganotschka batching does not help with quota you still under the same numbers as if you didnt batch – Linda Lawton - DaImTo May 29 '20 at 11:55
  • @DaImTo I have updated the print (the post above) with the message, but I'm receiveing it in portuguese and translate to English in print2. Follow the inner exception Error: "Unable to read data from transport connection. It was forced the cancel by remote server". – Rogerio Potenza May 29 '20 at 14:25
  • @ziganotschka I think it has been calculated for shorter time in folder creation. If I exchange the creation folder for creating files, it works perfectly. That's why I think the limitation is with folder creation. – Rogerio Potenza May 29 '20 at 14:28
  • This issue was resolved with this post => [here](https://stackoverflow.com/questions/62161904/google-drive-api-error-after-copying-multiple-files-net-cancel-connection-b) – Rogerio Potenza Jun 10 '20 at 13:11

0 Answers0