【问题标题】:Gmail API Python SDK batchModify not workingGmail API Python SDK批量修改不起作用
【发布时间】: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

【问题讨论】:

    标签: python gmail gmail-api


    【解决方案1】:

    糟糕,我忘记在batchModify() 请求之后致电execute()。对不起,如果我浪费了任何人的时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2017-08-02
      • 2015-04-22
      相关资源
      最近更新 更多