【发布时间】:2017-09-13 01:42:10
【问题描述】:
我正在尝试使用用于 python 的 Gmail API 客户端在批处理请求中将一些未读电子邮件标记为已读。这就是我正在做的:
response = service.users().messages().list(userId='me', labelIds=['Label_8','UNREAD']).execute()
msg_ids = []
for msg in response['messages']:
msg_id = msg['id']
msg_ids.append(msg_id)
# do something with the message
print("Marking messages as READ => %s" % msg_ids)
body = {'ids': msg_ids, 'addLabelIds': [], 'removeLabelIds': ['UNREAD']}
resp = service.users().messages().batchModify(userId='me', body=body)
print("Response ==> %s" % resp.body)
在我的测试中有2条未读消息,上面的最终输出是:
Response ==> {"ids": ["abc123xyz", "abc456xyz"], "removeLabelIds": ["UNREAD"]}
...但邮件未标记为已读。没有错误。但是,如果我在循环期间使用单个版本的 modify 将消息标记为单独读取,则它可以工作,如下所示:
response = service.users().messages().list(userId='me', labelIds=['Label_8','UNREAD']).execute()
msg_ids = []
for msg in response['messages']:
msg_id = msg['id']
msg_ids.append(msg_id)
# do something with the message
body = {'addLabelIds': [], 'removeLabelIds': ['UNREAD']}
service.users().messages().modify(userId='me', id=msg_id, body=body).execute()
但是为什么批处理请求不起作用?就像我说的,没有错误,我正在使用它exactly as the docs say。
【问题讨论】: