Gmail API 所有邮件 [英] Gmail API all messages

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

问题描述

我需要使用 gmail api 获取收件箱中的所有邮件.但我认为只有一种方法可以做到.

I need to get all messages in Inbox with gmail api. But I see only one way to do it.

  1. 获取消息列表(id, threadID)

GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages?labelIds=INBOX&key={YOUR_API_KEY}

  • 使用 id 获取循环中的所有消息

  • With id`s get all messages in loop

    While 
        GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages/147199d21bbaf5a5?key={YOUR_API_KEY}
    End of While
    

  • 但是这种方式需要 100500 个请求.有没有人知道如何通过一个请求获得所有消息(或只是 payload 字段)?

    But for this way needed 100500 request. Have anybody idea how to get with one request all messages(or just payload field)?

    推荐答案

    使用批处理并一次请求 100 条消息.您将需要发出 1000 个请求,但好消息是这很好,而且对每个人都更容易(无需在单个请求中下载 1GB 响应!).

    Use batch and request 100 messages at a time. You will need to make 1000 requests but the good news is that's quite fine and it'll be easier for everyone (no downloading 1GB response in a single request!).

    记录在:https://developers.google.com/gmail/api/guides/batch

    在 Stack Overflow 上还有其他一些人询问过批处理 Gmail Api,因此只需快速搜索即可找到答案和示例.

    There's a few other people that have asked about batching Gmail Api here on Stack Overflow, so just do a quick search to find answers and examples.

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

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