简体   繁体   English

获取邮件的Gmail API限制

[英]Gmail API limitations for getting mails

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. 据我所知,目前google的API每秒向其API提供10个请求( 来自他们的文档 ),并且看起来远远不足以让您轻松使用邮件。 I need to get all emails' headers (or at least senders and recipients). 我需要获取所有电子邮件的标题(或至少发件人和收件人)。 Is there anything better than waiting numberOfMails / 10 seconds? 有没有比等待numberOfMails / 10秒更好的东西?

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. 我目前正在从客户端JavaScript应用程序访问API,我正在考虑通过许多机器/应用程序为同一用户分发API调用,但是仍然不清楚它们的限制是否适用于gmail用户或注册的应用程序。

Anyway, hope to get some ideas what to do with it, with current quota it's completely not usable. 无论如何,希望得到一些想法如何处理它,目前的配额是完全无法使用的。

The 10 requests/second/user limit you quote isn't enforced at one-second granularity but a longer moving window. 您引用的10个请求/秒/用户限制不是以一秒钟的粒度强制执行,而是以更长的移动窗口强制执行。 You should be able to exceed that limit (ie 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). 批处理有助于提高吞吐量,但不允许您在长时间窗口内超过此限制(批处理中的100个请求仍计为100个请求)。 I would not send more than 50 or 100 requests in a batch or you will definitely notice some of them getting throttled (429). 我不会批量发送超过50或100个请求,或者你肯定会注意到其中一些请求受到限制(429)。

And yes, the project-wide limits are significantly more generous than 10 requests/second. 是的,项目范围的限制比10个请求/秒更加慷慨。

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: java代码是这样的:

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 . 问题的作者添加 :对于那些也遇到此问题的人: https//developers.google.com/gmail/api/guides/batchhttps://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. 虽然RpcBatch已被弃用,但它现在正在运行,每批限制为1000个请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM