我正在使用 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/