我想构建一个具有获取其他人的日历事件功能的网络应用程序。我已经注册了该应用程序https://apps.dev.microsoft.com/
并要求Calendars.Read
允许。我确信管理员已同意分配这些权限(我让他通过管理员同意页面来完成)。
![enter image description here](https://i.stack.imgur.com/7Pj1F.png)
下面是我的 ASP.Net 控制器代码,旨在测试事件 API。目标API是:
MicrosoftGraphCalendarApi = "https://graph.microsoft.com/v1.0/users/{0}/events";
public async Task<string> GetUserCalendar()
{
ConfidentialClientApplication cc =
new ConfidentialClientApplication(Globals.ClientId, Globals.RedirectUri,
new ClientCredential(Globals.ClientSecret),
null,
new TokenCache());
AuthenticationResult result =
await cc.AcquireTokenForClientAsync(new string[] { "https://graph.microsoft.com/.default" });
HttpClient client = new HttpClient();
string requestUrl = String.Format(Globals.MicrosoftGraphCalendarApi, "[email protected]");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync();
return json;
}
当被调用时,我似乎设法得到了accessToken
。然而,要求获得events
回应一个404
错误。以下是完整的回应:
{
StatusCode : 404,
ReasonPhrase: 'Not Found',
Version : 1.1,
Content : System.Net.Http.StreamContent,
Headers:
{
Transfer-Encoding: chunked
request-id: 34f1f9b3-34c9-444f-9037-5446884e3fb9
client-request-id: 34f1f9b3-34c9-444f-9037-5446884e3fb9
x-ms-ags-diagnostic:
{
"ServerInfo":
{
"DataCenter": "East Asia",
"Slice": "SliceA",
"ScaleUnit": "000",
"Host": "AGSFE_IN_2",
"ADSiteName": "HKG"
}
}
Duration: 1250.6509
Cache-Control: private
Date: Fri, 03 Nov 2017 02:53:03 GMT
Content-Type: application/json
}
}
System.Net.Http.HttpResponseMessage
我不知道问题出在哪里。请帮忙,谢谢。