Gmail API:如何将草稿移至收件箱,就像我们在 Gmail 中所做的那样 UI

Gmail API: How to move a draft into INBOX, like we can do in Gmail UI

Gmail API docs 指出

Messages and threads can have multiple labels associated with them; however, draft messages cannot have labels applied to them.

但是,我们可以使用 Gmail 网络将草稿移动到收件箱 UI。

我想使用 API 做同样的事情。如何做到这一点?

感谢@DalmTo,我找到了如下解决方案。

message = email.mime.text.MIMEText("This is the body")
message['to'] = "to@example.com"
message['from'] = "to@subject.com"
message['subject'] = "Test draft"
payload1 = {"message": {
    "raw": base64.urlsafe_b64encode(message.as_bytes()).decode("utf-8"),
    # "labelIds": ["INBOX"]  # This will cause an error
    }}
res1 = google.post("/gmail/v1/users/me/drafts", json=payload1)
    
payload2 = {"addLabelIds": ["INBOX"], "removeLabelIds":[]}
thread_id = res1.json()["message"]["threadId"]
res2 = google.post(f"/gmail/v1/users/me/threads/{thread_id}/modify", json=payload2)
# Or (both works)
# message_id = res1.json()["message"]["id"]
# res2 = google.post(f"/gmail/v1/users/me/messages/{thread_id}/modify", json=payload2)