How to retrieve contents of an itemAttachment via the Microsoft Graph API

前端 未结 2 973
轮回少年
轮回少年 2020-12-11 05:02

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

2条回答
  •  隐瞒了意图╮
    2020-12-11 05:34

    The official documentation: https://graph.microsoft.io/en-us/docs/api-reference/beta/api/attachment_get.htm . Use valid Bearer authentication access code, and check for appropriate Graph API permissions on the Azure management portal. Attachment is based64 encoded string, coming in the contentBytes field. Correct Uri for loading list of a message attachments is: https://graph.microsoft.com/beta/me/messages/[ message Id ]/attachments. Sample code to call attachments endpoint is below:

    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);
                }
            }
        }
    }
    

提交回复
热议问题