我想构建一个Web应用程序,它具有获取其他人的日历事件的功能。我已在https://apps.dev.microsoft.com/
注册该应用并请求Calendars.Read
权限。我确信管理员已同意分配这些权限(我允许他通过adminconsent页面执行此操作)。
下面是我的ASP.Net控制器代码,旨在测试Events 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, "lizhuowei@intl.zju.edu.cn");
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
我不知道问题可能在哪里。请帮助,谢谢。
答案 0 :(得分:2)
终于解决了。用户必须分享&#39;或者&#39;发布&#39;首先是目标日历。否则,即使得到管理员的同意,其他帐户也无法访问它。