如何通过Microsoft Graph API检索itemAttachment的内容 [英] How to retrieve contents of an itemAttachment via the Microsoft Graph API

查看:83
本文介绍了如何通过Microsoft Graph API检索itemAttachment的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently developing a solution which is retrieving e-mails via the Microsoft Graph API. In november 2015 Microsoft stated it is ready for production and I've read in another forum post that if you start now on developing using a Microsoft API, you should use the Graph API, since it is the future.

除了一件事情,一切都进行得很顺利.

Everything is going well except for one thing and that is the following.

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

I must retrieve e-mails. Inside these e-mails there are of course attachments. These attachments come in some variaties. fileAttachment (images, documents etc.), referenceAttachments and itemAttachments (outlook-item). The issue here is with the itemAttachments. An itemAttachment can be anything from an appointment to another message. The problem here is that I'm not able to get and retrieve the contentBytes in some way which is working for fileAttachments. A related object to itemAttachment is outlookItem. There is also a page with a description made for this outlookItem, but the examples and the details are missing. The user rights are set to Mail.Read and Mail.ReadWrite.

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

Links: General overview: http://graph.microsoft.io/docs/overview/overview Get outlookItem (empty?):

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

Example call and response I get. Please note the types of the attachments. 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内容? /a>.

I've tried to change the GET-statement by pasting the attachment id with or without the messages path and the expand feature (which is only supported one level deep), but I can't seem te find the solution. Something I've found is this question, which is kind of the same, however it is for the office365 unified API. How to retrieve ItemAttachment contents from Office 365 REST API?.

那么,问题是:如何通过Microsoft Graph API检索outlookItem的内容?我怎么知道会发生什么呢?谁能帮助我克服这个障碍.

So, the question: How can I retrieve the contents of an outlookItem via the Microsoft Graph API? And how do I know what to expect? Can anybody help me getting past this obstacle.

推荐答案

使用$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/zh-CN/graph/docs/api-reference/v1.0/api/attachment_get#request-2

这篇关于如何通过Microsoft Graph API检索itemAttachment的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆