Forum Discussion
Error when I try to get Presence from my Asp.Net web app
I'm trying to query a user's presence from an Asp.Net web app. Originally I wanted to do this using application level permissions but this may only be possible with delegated permissions?
In any case I have written some basic code to just login in the user and get their presence. However whenever I try to get the presence I get a Microsoft.Graph.Models.ODataErrors.ODataError exception with an error code of 403 'Forbidden'. All other graph calls appear to work okay, except for the requests for Presence.
If I log into Graph Explorer with the same user I am able to query the user's and other users' Presence using https://graph.microsoft.com/v1.0/me/presence and https://graph.microsoft.com/v1.0/users/{id}/presence
My code is below. What am I doing wrong?
var scopes = new[] { "https://graph.microsoft.com/.default" };
InteractiveBrowserCredential credential = new InteractiveBrowserCredential();
var graphClient = new GraphServiceClient(credential, scopes);
var result1 = await graphClient.Me.JoinedTeams.GetAsync(); // Works
var result2 = await graphClient.Me.Outlook.SupportedTimeZones.GetAsync(); // Works
var result3 = await graphClient.Users[userIdentities[0].ToString()].GetAsync(); // Works
var result4 = await graphClient.Groups.GetAsync(); // Works
var result5 = await graphClient.Me.Presence.GetAsync(); // Doesn't Work
var result6 = await graphClient.Users[userIdentities[0].ToString()].Presence.GetAsync(); // Doesn't Work