请求获取日历事件响应 404,给定分配的权限和使用 Microsoft Graph API 获得的 accessToken [英] Request to get calendar events responses 404, given the permission assigned and accessToken got using Microsoft Graph API
问题描述
我想构建一个具有获取其他人日历事件功能的 Web 应用程序.我已经在 https://apps.dev.microsoft.com/
上注册了该应用程序并请求了 Calendars.Read
权限.而且我确定管理员已同意分配这些权限(我让他通过 adminconsent 页面执行此操作).
I want to build a web application which has the function to get other peoples' calendar events. I has register the app on https://apps.dev.microsoft.com/
and requested Calendars.Read
permission. And I'm sure the Admin has consented to assign these permissions (which I let him to do through the adminconsent page).
下面是我的 ASP.Net 控制器代码,旨在测试事件 API.目标 API 是:
Below is my ASP.Net Controller code aimed to test the Events API. The targeted API is:
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
错误.以下是完整的回复:
When invoked, it seems I managed to get the accessToken
. However, the request to get events
responds a 404
error. Below is the complete response:
{
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
我不知道问题出在哪里.请帮忙,谢谢.
I have no idea where the issue may lie. Please help, thanks.
推荐答案
终于解决了.用户必须首先共享"或发布"目标日历.否则即使得到管理员的同意,其他帐户也无法访问它.
Finally solved. The user has to 'share' or 'publish' the targeted calendar first. Otherwise other accounts cannot get access to it even with the admin's consent.
这篇关于请求获取日历事件响应 404,给定分配的权限和使用 Microsoft Graph API 获得的 accessToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!