Google API JavaScript Client - Quota Error: User Rate Limit Exceeded

698 views Asked by At

I'm building a web app that that is going to perform certain tasks on our Google Analytics account but i'm getting errors due to 'userRateLimitExceeded'.

What I have at the moment:

(1) Run normal (unbatched) query for the management account list.

(2) Run a second query, batched, for all web properties on each account.

The first query runs as expected, the second batch query completes but every sub query has the same error 'Quota Error: User Rate Limit Exceeded.'.

From my understanding the client library implements a rate limiting mechanism which ensures this doesn't happen. Can anyone explain whats happening to help resolve this issue, highly likely I am doing something wrong. Thanks up front for any help you can give.

    (function(window){

    "use strict";

    var dataStore = new GlobalDataStore();      


    function handleAccountProperties(AccountProperties){
        console.log(AccountProperties);
    }

    function getAccountProperties(){
        var batch = gapi.client.newBatch();

        for (var i = 0; i < dataStore.accounts.length; i++) {
            var account = dataStore.accounts[0];
            var request = gapi.client.analytics.management.webproperties.list({
                'accountId': account.details.id
            });           
            batch.add(request);
        }

        batch.then(function(response){
            handleAccountProperties(response.result);
        }, function(reason){
             console.log('Error: ' + reason.result.error.message);
        });
    };

    function getAndHandleAccounts(){
        var request = gapi.client.analytics.management.accounts.list();
        request.then(function(response) {
            if(response.result.items && response.result.items.length) {
                for (var i = 0; i < response.result.items.length; i++) {
                    var account = new GoogleAnalyticsAccount();
                    account.details = response.result.items[i];
                    dataStore.accounts.push(account);
                }
                getAccountProperties();
            }
        });
    };

    function authorise(){
        var authData = {
            client_id: dataStore.clientID,
            scope: dataStore.scopes,
            immediate: false
        };

        gapi.auth.authorize(authData, function(response) {
            if (response.error) {
                console.error('shit went wrong');
            } else {
                gapi.client.load('analytics', 'v3').then(getAndHandleAccounts);
            }
        });
    };

    window.onload = authorise;

})(window);
0

There are 0 answers