如何在python 3中解析gmail messages.get()批处理响应

时间:2018-07-10 22:41:12

标签: python-3.x api gmail-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()

我如何访问每个请求的响应?我已经浏览了文档,但是没有公共方法来获取响应。

1 个答案:

答案 0 :(得分:0)

您可以在callback函数中访问每个请求的响应,该函数在您的示例中称为mycallbackfunc

def process_message(request_id, response, exception):
  if exception is not None:
    # Do something with the exception
    pass
  else:
    # Do something with the response
    pass

batch = BatchHttpRequest()
for msg_id in message_ids:
    batch.add(service.users().messages().get(userId = 'me', id = msg_id['id']), callback=process_message)
batch.execute()