python - 在新的 Gmail API 中批量提取电子邮件

标签 python google-api gmail-api

我正在使用 Google 新发布的 Gmail API 的 python 版本。

以下调用仅返回消息 ID 列表:

service.users().messages().list(userId = 'me').execute()

但是我只有一个消息 ID 列表,需要遍历它们并一个接一个地获取它们。

有没有办法在一次调用中获取 id 列表的整个消息内容? (类似于 Google Calendar API 中的操作方式)?

如果还不支持,Google 是否会考虑在 API 中添加此功能?

更新

这是对我有用的解决方案:
batch = BatchHttpRequest() 对于 message_ids 中的 msg_id: batch.add(service.users().messages().get(userId = 'me', id = msg_id['id']), callback = mycallbackfunc) batch.execute()

最佳答案

这是 Java 中的批处理请求示例,我使用线程 ID 获取所有线程。这可以很容易地适应您的需要。

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 requests
for (Thread thread : threads) {
    service.users().threads().get("me", threads.getId()).queue(b, bc);
}


b.execute();

关于python - 在新的 Gmail API 中批量提取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24562981/

相关文章:

python - 如何在 Gmail API 中正确设置 "In-Reply-To"和 "Reference" header

python - 重复数字序列 N 次并逐渐增加序列中的值 Python

google-api - Google API - 如何为用户获取别名电子邮件?

python - Google API(gmail 和电子表格): what more should I set up, 或者知道我缺少什么设置?

jquery - GMail API 分页使用 nextPageToken

python - 聚合 pandas 列中连续非 NaN 单元格的字符串,但不聚合整个列

python - 如何将用户定义类的实例转换为元组

angularjs - 带有 AngularJS 的 Google 登录按钮

java - 如何从 Google Custom Search API 获取超过 100 个结果

ios - 无法通过 gmail api 向多个发件人发送电子邮件