Reputation: 1372
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.
Upvotes: 2
Views: 3724
Reputation: 1726
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.
Upvotes: 4
Reputation: 7159
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.
Upvotes: 5