Get contact email addresses using Google People API in Javascript
<p>I wanted to retrieve the email address of the contacts for a user.
I am planning to use Google People API.
Here is my function to retrieve:</p>
<pre><code>function makeApiCall() {
    gapi.client.load('people', 'v1').then(function() {
        var request = gapi.client.people.people.connections.list({
            resourceName: 'people/me',
            pageSize: 200,
            fields: 'connections(resourceName)'
        });
        request.execute(function(resp) {
            if (resp.connections){
                var batch = gapi.client.newBatch(); 
                var emails = [];
                for(var i = 0; i &lt; resp.connections.length; i++){
                    var req = gapi.client.people.people.get({
                        resourceName: resp.connections[i].resourceName,
                        fields: &quot;emailAddresses(value)&quot;
                    });
                    batch.add(req);
                    req.then(function (email){
                        var idx = email.body.indexOf(&quot;{&quot;);
                        var jsonString = email.body.substring(idx &gt; 0 ? idx : 0); 
                        var obj;
                        try {
                            obj = JSON.parse(jsonString);
                            if (obj.emailAddresses){ 
                                for (j = 0; j &lt; obj.emailAddresses.length; j++){ 
                                    emails.push(obj.emailAddresses[j].value);
                                } 
                            }
                        } catch (err) {
                            console.error(email);
                        }
                    })
                }
                batch.then(function (){
                    console.log(emails); 
                }, function (err){
                    console.error(err);
                }); 
            } else {
                console.error(&quot;Error&quot;, resp);
            }
        });
    }, function (err){
        console.error(err);
    });
}
</code></pre>
<p>Basically, I am fetching 200 connections to retrieve their resourceName.<br />
This reresourceName will be used to get the email address of the user.<br />
I am using a batch request to fetch the 200 users email.</p>
<p>The issue is that, for some users, I am getting the following error:</p>
<pre><code>{
  &quot;error&quot;: {
    &quot;code&quot;: 429,
    &quot;message&quot;: &quot;Insufficient tokens for quota group and limit ReadGroupUSER-100s using the limit by ID 991457241470@515501272068.&quot;,
    &quot;status&quot;: &quot;RESOURCE_EXHAUSTED&quot;,
    &quot;details&quot;: [
      {
        &quot;@type&quot;: &quot;type.googleapis.com/google.rpc.Help&quot;,
        &quot;links&quot;: [
          {
            &quot;description&quot;: &quot;Google developer console API key&quot;,
            &quot;url&quot;: &quot;https://console.developers.google.com/project/991457241470/apiui/credential&quot;
          }
        ]
      }
    ]
  }
}
</code></pre>
<p>What could be the reason and how can I resolve this issue?</p>