【问题标题】:How to parse the gmail messages.get() batch response in python 3如何在 python 3 中解析 gmail messages.get() 批处理响应
【发布时间】:2018-12-18 20:51:21
【问题描述】:
我已使用以下代码批处理并执行了我的请求:
batch = BatchHttpRequest()
for msg_id in message_ids:
batch.add(service.users().messages().get(userId = 'me', id = msg_id['id']), callback = mycallbackfunc)
batch.execute()
如何访问每个请求的响应?我查看了文档,但没有公共方法可以获取响应。
【问题讨论】:
标签:
python-3.x
api
gmail-api
【解决方案1】:
您在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()