Демон Microsoft Graph API — ошибка: сообщение ResourceNotFound: ресурс не найден ⇐ C#
-
Anonymous
Демон Microsoft Graph API — ошибка: сообщение ResourceNotFound: ресурс не найден
I'm trying to create a daemon using Microsoft Graph API v1.0.
I've registered my app with application permission Calendars.ReadWrite and User.Read.All with granted admin consent.
I get the access token correctly and I call GetUserId that returns the user id for setting requestURI.
After that I want to retrieve Outlook Calendar:
var id = await GetUserId(result.AccessToken); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); String requestURI = $"https://graph.microsoft.com/v1.0/users/{id}/calendars"; var response = await httpClient.GetAsync(requestURI); var responseString = await response.Content.ReadAsStringAsync(); but I get this error:
{ "error": { "code": "ResourceNotFound", "message": "Resource could not be discovered.", "innerError": { "request-id": "5ecd547b-9281-4824-94e5-095691e759aa", "date": "2020-01-14T16:44:16" } } } When I set requestURI to users/{id} or organization the request works fine, but adding /calendars, /events, or /mailFolder results in the above error.
I think my problem is that I used a Personal Account. Do I need to use a Work or School Account? Is it possible to use a Personal Account? Is there another reason for my error?
Update: Code for retrieving a token:
app = ConfidentialClientApplicationBuilder .Create(ClientId) .WithClientSecret(ClientSecret) .WithAuthority($"https://login.microsoftonline.com/{Tena ... rosoft.com") .Build(); string[] scopesClient = new string[] { $"https://graph.microsoft.com/.default" }; AuthenticationResult result = null; try { result = await app.AcquireTokenForClient(scopesClient).ExecuteAsync(); } catch (MsalServiceException ex) when(ex.Message.Contains("AADSTS70011")) { }
Источник: https://stackoverflow.com/questions/597 ... -could-not
I'm trying to create a daemon using Microsoft Graph API v1.0.
I've registered my app with application permission Calendars.ReadWrite and User.Read.All with granted admin consent.
I get the access token correctly and I call GetUserId that returns the user id for setting requestURI.
After that I want to retrieve Outlook Calendar:
var id = await GetUserId(result.AccessToken); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); String requestURI = $"https://graph.microsoft.com/v1.0/users/{id}/calendars"; var response = await httpClient.GetAsync(requestURI); var responseString = await response.Content.ReadAsStringAsync(); but I get this error:
{ "error": { "code": "ResourceNotFound", "message": "Resource could not be discovered.", "innerError": { "request-id": "5ecd547b-9281-4824-94e5-095691e759aa", "date": "2020-01-14T16:44:16" } } } When I set requestURI to users/{id} or organization the request works fine, but adding /calendars, /events, or /mailFolder results in the above error.
I think my problem is that I used a Personal Account. Do I need to use a Work or School Account? Is it possible to use a Personal Account? Is there another reason for my error?
Update: Code for retrieving a token:
app = ConfidentialClientApplicationBuilder .Create(ClientId) .WithClientSecret(ClientSecret) .WithAuthority($"https://login.microsoftonline.com/{Tena ... rosoft.com") .Build(); string[] scopesClient = new string[] { $"https://graph.microsoft.com/.default" }; AuthenticationResult result = null; try { result = await app.AcquireTokenForClient(scopesClient).ExecuteAsync(); } catch (MsalServiceException ex) when(ex.Message.Contains("AADSTS70011")) { }
Источник: https://stackoverflow.com/questions/597 ... -could-not
Мобильная версия