【问题标题】:Outlook API Get Messages not returning Attachment collectionOutlook API 获取消息不返回附件集合
【发布时间】:2016-04-28 02:06:34
【问题描述】:

我正在使用 Outlook Mail REST API 来获取用户电子邮件集合的 JSON 对象,并在自定义 Web 界面中显示数据。我需要显示一个电子邮件列表,并且列表中的每封电子邮件都需要一个指示该特定电子邮件的附件数量的指示器。

我正在使用 Get Messages from Outlook Mail REST API reference #Getmessages 路由来获取执行此操作所需的所有数据。但是,当我在我的$select 中指定我想要Attachments 时,我从来没有得到每封电子邮件的附件集合;它只是丢失了。

我可以通过对每封电子邮件的单独请求来获取每封电子邮件的附件集合,如果我需要一次对 100 封电子邮件进行附件计数,这将很难看。

据此:(https://msdn.microsoft.com/office/office365/api/complex-types-for-mail-contacts-calendar#RESTAPIResourcesMessage) 我应该能够在获取消息时指定是否需要附件集合,但它不起作用。我正在使用 Node.js 来获取电子邮件集合:

var requestUrl = "https://outlook.office.com/api/v2.0/me/messages";

var queryParams = {
    '$select': 'Subject, ReceivedDateTime, From, ToRecipients, HasAttachments, Attachments, WebLink, CcRecipients, Body',
    '$orderby': 'ReceivedDateTime desc',
    '$filter' : dateString,
    '$top': 300
};

...

Returned Email Object in Collection

$select 中的每个选项在我包含或排除它时都可以正常工作,但 Attachments 总是丢失。有人有解决办法吗?

【问题讨论】:

    标签: node.js outlook outlook-restapi


    【解决方案1】:

    Attachments 是一个导航属性,因此您需要通过附加一个$expand 参数来请求它“扩展”:

    https://outlook.office.com/api/v2.0/me/mailfolders/inbox/messages?
      $select=Subject,Attachments&$filter=HasAttachments eq true&$expand=Attachments
    
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多