簡體   English   中英

Office 365 REST API(Python)將電子郵件標記為已讀

[英]Office 365 REST API (Python) Mark Email as Read

我確定我做了一些簡單的錯誤,但我不能為我的生活弄清楚如何將“IsRead”屬性設置為true。 這是我的流程的最后一步,它獲取了一個過濾的消息列表,並存儲和處理任何附件。

根據文檔“IsRead”是可寫的: http//msdn.microsoft.com/office%5Coffice365%5CAPi/complex-types-for-mail-contacts-calendar#ResourcesMessage

http://msdn.microsoft.com/office%5Coffice365%5CAPi/mail-rest-operations#MessageoperationsUpdatemessages

我正在使用python 2.7和請求模塊:

# once file acquired mark the email as read
params = {'IsRead':'True'}
base_email_url = u'https://outlook.office365.com/api/v1.0/me/messages/{0}'.format( msgId )
response = requests.patch(base_email_url, params, auth=(email,pwd))
log.debug( response )

回復的反應如下:

{"error":{"code":"ErrorInvalidRequest","message":"Cannot read the request body."}}

我的要求有什么問題?

乍一看它看起來還不錯。 我想知道Content-Type標頭是不是被設置為“application / json”或者是那些行。 嘗試獲取網絡跟蹤並驗證請求是否類似於:

PATCH https://outlook.office365.com/api/v1.0/Me/Messages('msgid') HTTP/1.1
Accept: application/json;odata.metadata=full
Authorization: Bearer <token>
Content-Type: application/json;odata.metadata=full
Host: outlook.office365.com
Content-Length: 24
Expect: 100-continue
Connection: Keep-Alive

{
  "IsRead": "true"
}

好吧,我有自己的答案,這確實是一件簡單的事情。 沒有完全閱讀PATCH與GET或POST的不同之處是錯誤的。 簡而言之,確保為正確的內容類型設置標題非常重要。

這是工作代碼:

# once file acquired mark the email as read
changes = {u'IsRead':u'True'}
headers = {'Content-Type': 'application/json'}
json_changes = json.dumps(changes)
base_email_url = u'https://outlook.office365.com/api/v1.0/me/messages/{0}'.format( msgId )
response = requests.patch(base_email_url, data=json_changes, auth=__AUTH, headers=headers)
log.debug( response )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM