使用Microsoft Graph API订阅Outlook推送通知时出现400错误的请求错误

问题描述:

我正在尝试创建一个订阅,以使用Microsoft Graph API通过推送通知获取Outlook电子邮件@提及.我正在使用

I am trying to create a subscription to get Outlook emails @mentions via Push Notification using Microsoft Graph API. I am using this documentation for reference/

我在portal.azure.com中创建了一个应用,并在"Microsoft Graph" API下提供了读取用户邮件"所需的权限,并且管理员通过Microsoft Demo租户同意了该请求.但是我仍然无法订阅Microsoft Graph Push Notification REST API,并且出现400 Bad Request错误.

I created an app in portal.azure.com and provided Required permission on "Read user mail" under "Microsoft Graph" API and admin consented it through Microsoft Demo tenant. But I am still not able to subscribe to the Microsoft Graph Push Notification REST API and I am getting 400 Bad Request error.

我还尝试在Microsoft Graph API下向portal.azure.com中的应用程序授予所有权限,并且管理员再次通过我的Microsoft演示租户同意了该应用程序,但我仍然遇到相同的400错误请求错误.

I also tried granting all permissions to the app in portal.azure.com under the Microsoft Graph API and again admin consented it through my Microsoft demo tenant but I am still getting same 400 bad request error.

我正在使用以下代码创建订阅:

I am using the following code to create a subscription:

private static void Subscribe(AuthenticationHeaderValue authHeader) 
{
    using(HttpClient _httpClient = new HttpClient()) 
    {
       _httpClient.BaseAddress = new Uri("https://graph.microsoft.com");
       _httpClient.DefaultRequestHeaders.Accept.Clear();
       _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
       _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
       _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
       _httpClient.DefaultRequestHeaders.Authorization = authHeader;

       // connect to the REST endpoint to subscribe   
       var json = @"{
                       'changetype':'created,updated',
                       'notificationurl': 'http://requestbin.fullcontact.com/two54stw/',
                       'resource': 'me/mailfolder(\'Inbox\')/messages',
                       'clientstate': 'secretclientvalue'
                   }";

       HttpContent contentPost = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
       HttpResponseMessage subscribe = _httpClient.PostAsync($"v1.0/subscriptions", contentPost).Result;
       Console.WriteLine("New subscription created!");
    }
}

有人解决过类似的问题,以创建推送通知订阅"来获取Outlook电子邮件,请帮忙吗?

Has anyone worked on a similar issue to create a Push notification Subscription to get Outlook emails and can please help?

Neha.基于400 Bad Request错误,我认为notificationurl配置不正确.

Neha.Based on the 400 Bad Request error, I assume that the notificationurl is not configured correctly.

请参阅此文章,我遵循了此处.它对我有用.

Please refer to this article and I followed the sample from here.It works for me.

获取令牌:

响应: