Reputation: 4319
I am trying to get a list of planner plans associated with a user. I can do this in Graph Explorer (logged in with my work Microsoft account) using the following API call:
https://graph.microsoft.com/v1.0/users/<my-email>/planner/plans
However, I need to use a token from my console app, as I need to run it as a scheduled task with no user intervention. From my app I get an access denied error:
401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied.
I can successfully call "generic" methods (such as https://graph.microsoft.com/v1.0/groups
) but not something specific to a user.
I am getting my token using:
context = new AuthenticationContext("https://login.microsoftonline.com/<my_tenant");
context.AcquireTokenAsync("https://graph.microsoft.com", new ClientCredential(clientId, appKey));
How can I give this token the necessary permissions to read stuff like planner? I've tried in the Azure Portal under the Azure AD blade:
Upvotes: 0
Views: 295
Reputation: 1138
According to your description, I assume you want to list the plans of a user.
Based on my test, we can use the follow simple code:
public PlanClientService()
{
_serviceClient = GraphSdkHelper.GetGraphServiceClient();
}
public async Task<IList<PlannerPlan>> PlannerPlansAsync()
{
var plans = await _serviceClient.Me.Planner.Plans.Request().GetAsync();
return plans;
}
We can refer to the simple code for more detail.
And according to the error description, you should add the Group.Read.All, Group.ReadWrite.All
permission when you get the accesstoken.
Upvotes: 2