2
votes

As I understand currently google's API provides 10 requests per second to its API (from their docs), and it looks to be far from enough for comfortable work with mail. I need to get all emails' headers (or at least senders and recipients). Is there anything better than waiting numberOfMails / 10 seconds?

I'm currently accessing API from client side JavaScript application, I'm thinking of distributing API calls for the same user over a number of machines/applications, but's still unclear if their limits apply to gmail user or registered application.

Anyway, hope to get some ideas what to do with it, with current quota it's completely not usable.

2
The page you linked to states pretty clearly the usage limits: 10,000,000,000 quota units per day for all application requests, and 10 requests per second per gmail user.Frxstrem
@Frxstrem is there something better then getting emails one by one then?Artem Volkhin
@ArtemVolkhin I answered this question. Maybe you have the same question: stackoverflow.com/questions/24562981/…gitter
@gitter looks good, I'll give it a tryArtem Volkhin
@gitter it works (with limitation of 1000 request per batch -- developers.google.com/gmail/api/guides/batch) add it as an answer and I'll accept itArtem Volkhin

2 Answers

4
votes

You can use batch requests to send multiple requests together. I spent a whole day this week figuring this out. The java code goes like this:

BatchRequest batchRequest = service.batch();
//callback function. (Can also define different callbacks for each request, as required)
JsonBatchCallback<Thread> callback = new JsonBatchCallback<Thread>() {

    @Override
    public void onSuccess(Thread t, HttpHeaders responseHeaders)
        throws IOException {
        System.out.println(t.getMessages().get(0).getPayload().getBody().getData());
    }

    @Override
    public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
        throws IOException {

    }
};

// queuing requests on the batch request
for (Thread thread : threads) {
    service.users().threads().get("me", threads.getId()).queue(batchRequest, callback);
 }


batchRequest.execute();

Added by question's author: for those who also have this problem: https://developers.google.com/gmail/api/guides/batch and https://developers.google.com/api-client-library/javascript/features/rpcbatch. Although RpcBatch is deprecated it's working now and with limitation of 1000 request per batch.

5
votes

The 10 requests/second/user limit you quote isn't enforced at one-second granularity but a longer moving window. You should be able to exceed that limit (i.e. significantly) for some number of seconds before you get pushback. It's intentionally written to allow short-term bursts for a user, etc.

Batching will help with throughput but will not allow you to exceed this limit over a long window (100 requests in batch still counts as 100 requests). I would not send more than 50 or 100 requests in a batch or you will definitely notice some of them getting throttled (429).

And yes, the project-wide limits are significantly more generous than 10 requests/second.