Bar*_*man 24 python google-api gmail-api
我正在使用Google新发布的Gmail API的python版本.
以下调用仅返回消息ID列表:
service.users().messages().list(userId = 'me').execute()
Run Code Online (Sandbox Code Playgroud)
但后来我只有一个消息ID列表,需要迭代它们并逐个获取它们.
有没有办法在单个调用中获取id列表的整个消息内容?(类似于在Google Calendar API中完成的操作)?
如果还不支持,Google会考虑在API中添加这些内容吗?
这是适合我的解决方案:
batch = BatchHttpRequest()
for msg_id in message_ids:
batch.add(service.users().messages().get(userId = 'me', id = msg_id['id']), callback = mycallbackfunc)
batch.execute()
git*_*ter 18
以下是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();
Run Code Online (Sandbox Code Playgroud)
Bar*_*man 11
这是适合我的解决方案:
batch = BatchHttpRequest()
for msg_id in message_ids:
batch.add(service.users().messages().get(userId='me', id=msg_id['id']), callback=mycallbackfunc)
batch.execute()
Run Code Online (Sandbox Code Playgroud)