7

我目前正在开发一种通过 Microsoft Graph API 检索电子邮件的解决方案。2015 年 11 月,Microsoft 表示它已准备好投入生产,我在另一篇论坛帖子中读到,如果您现在开始使用 Microsoft API 进行开发,您应该使用 Graph API,因为它是未来。

一切都很顺利,除了一件事,那就是以下。

我必须检索电子邮件。在这些电子邮件中当然有附件。这些附件有一些变化。fileAttachment(图像、文档等)、referenceAttachments 和 itemAttachments(outlook-item)。这里的问题在于 itemAttachments。itemAttachment 可以是从约会到另一条消息的任何内容。这里的问题是我无法以某种适用于 fileAttachments 的方式获取和检索 contentBytes。与 itemAttachment 相关的对象是 outlookItem。还有一个页面对此outlookItem 进行了描述,但缺少示例和详细信息。用户权限设置为 Mail.Read 和 Mail.ReadWrite。

链接:一般概述:http : //graph.microsoft.io/docs/overview/overview 获取 outlookItem(空?):

我得到的示例呼叫和响应。请注意附件的类型。 https://graph.microsoft.com/v1.0 /users/ /messages/ /attachments

{
  "@odata.context": "link",
  "value": [
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "id": "AAMkAGU2NmIwMTcxLTljYzUtNGRiMi1hZjczLTllNzhiZDRiNWZlZABGAAAAPAD_Lx_gimDGRqSr98J_O_e6BwDcWyYHlO7rS5_XpLHCx6NSAAIMC0V-AADcWyYHlO7rS5_XpLHCx6NSAAIMC6RgAAABEgAQAGhN_vm1RlBPt7V4N9a89UY=",
      "lastModifiedDateTime": "2016-01-13T14:25:33Z",
      "name": "image001.png",
      "contentType": "image/png",
      "size": 5077,
      "isInline": true,
      "contentId": "image001.png@01D14E16.A3A32480",
      "contentLocation": null,
      "contentBytes": "iVBORw0KGgoAAAANSUhEUgAAAKAAAACCCAIAAABOyVRHAAAAAXNSR0IArs4c6QAAEndJREFUeF7tXQ1QFFe2bkbU... (truncated)"
    },
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "id": "AAMkAGU2NmIwMTcxLTljYzUtNGRiMi1hZjczLTllNzhiZDRiNWZlZABGAAAAPAD_Lx_gimDGRqSr98J_O_e6BwDcWyYHlO7rS5_XpLHCx6NSAAIMC0V-AADcWyYHlO7rS5_XpLHCx6NSAAIMC6RgAAABEgAQAFnSLgIC5wZOosmLtBWK8gE=",
      "lastModifiedDateTime": "2016-01-13T14:25:34Z",
      "name": "image002.png",
      "contentType": "image/png",
      "size": 3722,
      "isInline": true,
      "contentId": "image002.png@01D14E16.A3A32480",
      "contentLocation": null,
      "contentBytes": "iVBORw0KGgoAAAANSUhEUgAAAPoAAABSCAYAAAB9o8m+AAAAGXRFWHRTb... (truncated)"
    },
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "id": "AAMkAGU2NmIwMTcxLTljYzUtNGRiMi1hZjczLTllNzhiZDRiNWZlZABGAAAAPAD_Lx_gimDGRqSr98J_O_e6BwDcWyYHlO7rS5_XpLHCx6NSAAIMC0V-AADcWyYHlO7rS5_XpLHCx6NSAAIMC6RgAAABEgAQANOuw7m8sW1Ot3MivYQ5OYU=",
      "lastModifiedDateTime": "2016-01-13T14:25:24Z",
      "name": "Knipsel.PNG",
      "contentType": null,
      "size": 7641,
      "isInline": false,
      "contentId": null,
      "contentLocation": null,
      "contentBytes": "iVBORw0KGgoAAAANSUhEUgAAAKAAAACCCAYAAADBq8MQAAA... (truncated)"
    },
    {
      "@odata.type": "#microsoft.graph.itemAttachment",
      "id": "AAMkAGU2NmIwMTcxLTljYzUtNGRiMi1hZjczLTllNzhiZDRiNWZlZABGAAAAPAD_Lx_gimDGRqSr98J_O_e6BwDcWyYHlO7rS5_XpLHCx6NSAAIMC0V-AADcWyYHlO7rS5_XpLHCx6NSAAIMC6RgAAABEgAQAPEUC740tjtAlNTe8NpopUI=",
      "lastModifiedDateTime": "2016-01-14T15:55:07Z",
      "name": "RE: Test met plaatje",
      "contentType": null,
      "size": 36972,
      "isInline": false
    }
  ]
}

我试图通过粘贴带有或不带有消息路径和扩展功能(仅支持一层深度)的附件 id 来更改 GET 语句,但我似乎找不到解决方案。我发现的是这个问题,有点相同,但它适用于 office365 统一 API。如何从 Office 365 REST API 检索 ItemAttachment 内容?.

那么问题来了:如何通过 Microsoft Graph API 检索 outlookItem 的内容?我怎么知道会发生什么?任何人都可以帮助我克服这个障碍。

4

2 回答 2

4

使用$expand选项:

GET https://graph.microsoft.com/v1.0/me/messages('AAMkADA1M-zAAA=')/attachments('AAMkADA1M-CJKtzmnlcqVgqI=')/?$expand=microsoft.graph.itemattachment/item 

回复:

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('d1a2fae9-db66-4cc9-8133-2184c77af1b8')/messages('AAMkADA1M-zAAA%3D')/attachments/$entity",
  "@odata.type":"#microsoft.graph.itemAttachment",
  "id":"AAMkADA1MCJKtzmnlcqVgqI=",
  "lastModifiedDateTime":"2017-07-21T00:20:34Z",
  "name":"Reminder - please bring laptop",
  "contentType":null,
  "size":32005,
  "isInline":false,
  "item@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('d1a2fae9-db66-4cc9-8133-2184c77af1b8')/messages('AAMkADA1M-zAAA%3D')/attachments('AAMkADA1M-CJKtzmnlcqVgqI%3D')/microsoft.graph.itemAttachment/item/$entity",
  "item":{
    "@odata.type":"#microsoft.graph.message",
    "id":"",
    "createdDateTime":"2017-07-21T00:20:41Z",
    "lastModifiedDateTime":"2017-07-21T00:20:34Z",
    "receivedDateTime":"2017-07-21T00:19:55Z",
    "sentDateTime":"2017-07-21T00:19:52Z",
    "hasAttachments":false,
    "internetMessageId":"<BY2PR15MB05189A084C01F466709E414F9CA40@BY2PR15MB0518.namprd15.prod.outlook.com>",
    "subject":"Reminder - please bring laptop",
    "importance":"normal",
    "conversationId":"AAQkADA1MzMyOGI4LTlkZDctNDkzYy05M2RiLTdiN2E1NDE3MTRkOQAQAMG_NSCMBqdKrLa2EmR-lO0=",
    "isDeliveryReceiptRequested":false,
    "isReadReceiptRequested":false,
    "isRead":false,
    "isDraft":false,
    "webLink":"https://outlook.office365.com/owa/?ItemID=AAMkADA1M3MTRkOQAAAA%3D%3D&exvsurl=1&viewmodel=ReadMessageItem",
    "body":{
      "contentType":"html",
      "content":"<html><head>\r\n</head>\r\n<body>\r\n</body>\r\n</html>"
    },
    "sender":{
      "emailAddress":{
        "name":"Adele Vance",
        "address":"AdeleV@contoso.onmicrosoft.com"
      }
    },
    "from":{
      "emailAddress":{
        "name":"Adele Vance",
        "address":"AdeleV@contoso.onmicrosoft.com"
      }
    },
    "toRecipients":[
      {
        "emailAddress":{
          "name":"Alex Wilbur",
          "address":"AlexW@contoso.onmicrosoft.com"
        }
      }
    ],
    "ccRecipients":[
      {
        "emailAddress":{
          "name":"Adele Vance",
          "address":"AdeleV@contoso.onmicrosoft.com"
        }
      }
    ]
  }
}

来源:https ://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/attachment_get#request-2

于 2018-01-18T01:34:29.437 回答
0

官方文档:https ://graph.microsoft.io/en-us/docs/api-reference/beta/api/attachment_get.htm 。使用有效的 Bearer 身份验证访问代码,并在 Azure 管理门户上检查适当的 Graph API 权限。附件是基于 64 位编码的字符串,来自contentBytes字段。用于加载消息附件列表的正确 Uri 是:https://graph.microsoft.com/beta/me/messages/[ message Id ]/attachments。调用附件端点的示例代码如下:

using (var client = new HttpClient())
{
    using (var request = new HttpRequestMessage(HttpMethod.Get, 
        "https://graph.microsoft.com/beta/me/messages/..id../attachments"))
    {
        request.Headers.Authorization = 
            new AuthenticationHeaderValue("Bearer", "...valid access token...");

        using (HttpResponseMessage response = await client.SendAsync(request))
        {
            if (response.StatusCode == HttpStatusCode.OK)
            {
                result = await response.Content.ReadAsStringAsync();
                var json = JObject.Parse(result);
            }
        }
    }
}
于 2016-12-08T23:17:52.137 回答