如何解析python 3中的gmailmessages.get()批处理响应



我已经使用以下代码批处理并执行了我的请求:

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

如何访问每个请求的响应?我已经查看了文档,但没有公开的方法来获得回复。

您可以访问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()

最新更新