最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Gmail API limitations for getting mails - Stack Overflow

programmeradmin4浏览0评论

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 fortable 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 pletely not usable.

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 fortable 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 pletely not usable.

Share Improve this question asked Jul 5, 2014 at 17:35 Artem VolkhinArtem Volkhin 1,3728 silver badges22 bronze badges 4
  • 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. – Freyja Commented Jul 5, 2014 at 17:47
  • @Frxstrem is there something better then getting emails one by one then? – Artem Volkhin Commented Jul 5, 2014 at 17:51
  • 1 @ArtemVolkhin I answered this question. Maybe you have the same question: stackoverflow./questions/24562981/… – gitter Commented Jul 5, 2014 at 19:48
  • @gitter it works (with limitation of 1000 request per batch -- developers.google./gmail/api/guides/batch) add it as an answer and I'll accept it – Artem Volkhin Commented Jul 5, 2014 at 20:28
Add a ment  | 

2 Answers 2

Reset to default 5

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.

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./gmail/api/guides/batch and https://developers.google./api-client-library/javascript/features/rpcbatch. Although RpcBatch is deprecated it's working now and with limitation of 1000 request per batch.

发布评论

评论列表(0)

  1. 暂无评论