【问题标题】:Office 365 REST API (Python) Mark Email as ReadOffice 365 REST API (Python) 将电子邮件标记为已读
【发布时间】:2014-12-16 02:53:52
【问题描述】:

我确定我做错了一些简单的事情,但我一生都无法弄清楚如何将“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 和 requests 模块:

# 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."}}

我的请求有什么问题?

【问题讨论】:

    标签: python rest python-2.7 office365


    【解决方案1】:

    乍一看,它看起来不错。我想知道 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"
    }
    

    【讨论】:

    • 哈哈,我只是在输入我发现的内容,您是对的,先生。
    【解决方案2】:

    嗯,我自己有一个答案,这确实是一件简单的事情。 没有完全阅读 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 )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-24
      • 2015-04-10
      • 1970-01-01
      • 2015-01-15
      • 2016-06-06
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多