我已经使用以下代码批量处理并执行了请求:
batch = BatchHttpRequest()
for msg_id in message_ids:
batch.add(service.users().messages().get(userId = 'me', id = msg_id['id']), callback = mycallbackfunc)
batch.execute()
我如何访问每个请求的响应?我已经浏览了文档,但是没有公共方法来获取响应。
答案 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()