问题
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).
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;
}
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.
回答1:
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.
来源:https://stackoverflow.com/questions/47087825/request-to-get-calendar-events-responses-404-given-the-permission-assigned-and