26

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

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

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

但后来我只有一个消息 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()

4

2 回答 2

20

这是 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();
于 2014-07-05T13:04:41.643 回答
14

这是对我有用的解决方案:

batch = BatchHttpRequest()
for msg_id in message_ids:
    batch.add(service.users().messages().get(userId='me', id=msg_id['id']), callback=mycallbackfunc)
batch.execute()
于 2014-08-14T06:46:14.950 回答