add multiple events in google calendar witch batch

Hi all I am trying to insert multiple events into google calendar (events count are 67) . Everything works good but I have got sometime error like

     errors: [{domain: "usageLimits", reason: "rateLimitExceeded", message: "Rate Limit Exceeded"

I think that mean that I can not do so much calls.

I have write this code

        var makeRequest = function(resource) {
            console.log(resource);
            var request = gapi.client.calendar.events.insert({
              calendarId: 'primary',
              resource: resource,
            });
            request.execute(function(resp) {
              console.log(resp);
            });
          };

          for (var j = 0; j < events.length; j++) {
            makeRequest(events[j]);
          }

I know that I need to use batch like var batch = gapi.client.newBatch(); to avoid that problem but didn't understand how ... I looked here for some help Google Calendar javascript api - Add multiple events

Please help me to figure out how can I handle this problem.


rateLimitExceeded is flood protection you are going to fast. You will need to slow your application down.

The apis limit your access by something called quota. There are user quotas and application quotas. In the image below you can see that my user based quota is 600 request per minute but my application based quota will be 10000 requests per minute.

enter image description here

Batching does not save you on quota as each request within the batch counts as a single request. In some cases sending batch requests will increase the chance that you will see rateLimitExceeded as the batching is going to fast. The only thing batching saves you on is the number of HTTP calls.