2

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.

4

2 回答 2

5

您引用的 10 个请求/秒/用户限制不是在一秒的粒度上强制执行的,而是一个更长的移动窗口。您应该能够在受到回击之前超过该限制(即显着)几秒钟。它是故意编写的,以允许用户进行短期爆发等。

批处理将有助于提高吞吐量,但不允许您在长窗口内超过此限制(批处理中的 100 个请求仍算作 100 个请求)。我不会一次发送超过 50 或 100 个请求,否则您肯定会注意到其中一些请求受到限制 (429)。

是的,项目范围的限制比 10 个请求/秒要慷慨得多。

于 2014-07-07T22:29:00.377 回答
4

您可以使用批处理请求一起发送多个请求。这周我花了一整天的时间来解决这个问题。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();

由问题作者添加:对于那些也有这个问题的人:https ://developers.google.com/gmail/api/guides/batch和https://developers.google.com/api-client-library/javascript/features /rpcbatch。尽管 RpcBatch 已被弃用,但它现在可以正常工作,并且每个批次的请求限制为 1000 个。

于 2014-07-05T20:51:02.163 回答