用于获取邮件的Gmail API限制 [英] Gmail API limitations for getting mails

查看:291
本文介绍了用于获取邮件的Gmail API限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据了解,目前,Google的API每秒可以为其API提供10个请求( from他们的文档),它看起来远远不够用于舒适的邮件工作。我需要收到所有电子邮件的标题(或至少是发件人和收件人)。有没有比等待 numberOfMails / 10 秒更好?



我正在从客户端JavaScript应用程序访问API我正在考虑通过一些机器/应用程序为同一用户分发API调用,但是仍然不清楚其限制是否适用于Gmail用户或注册的应用程序。



无论如何,希望得到一些想法如何处理,目前的配额完全不可用。

解决方案

可以使用批处理请求一起发送多个请求。我本周花了整整一个礼拜了。 java代码如下所示:

  BatchRequest b = service.batch(); 
//回调函数。 (也可以根据需要为每个请求定义不同的回调)
JsonBatchCallback< Thread> bc = new JsonBatchCallback< Thread>(){

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

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

}
} ;

//批处理请求的排队请求
(线程线程:线程){
service.users()。threads()。get(me,threads。 getId())。queue(b,bc);
}


b.execute();

由问题作者添加:对于那些也有这个问题的人:一个href =https://developers.google.com/gmail/api/guides/batch =nofollow> https://developers.google.com/gmail/api/guides/batch 和 https://developers.google.com/api-client-library/javascript /特征/ rpcbatch 。虽然RpcBatch已被弃用,但它现在正在工作,并且限制每批次1000个请求。


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.

解决方案

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 b = service.batch();
//callback function. (Can also define different callbacks for each request, as required)
JsonBatchCallback<Thread> bc = 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(b, bc);
 }


b.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.

这篇关于用于获取邮件的Gmail API限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆