-->

Using Microsoft graph to read all users calendars

2020-04-21 05:47发布

问题:

I gave my application the following scopes:

SCOPES = [ "Calendars.Read", "User.Read.All" ]

I got an access token. With this token I am able to get the users and I get two users back which is correct.

When I then ask for the calendar of myself (admin):

https://graph.microsoft.com/v1.0/users/stijn@temponia.onmicrosoft.com/calendarview?startDateTime=#{start_date.to_s}&endDateTime=#{end_date.to_s}

This also works perfectly. However when I do this for the other user:

https://graph.microsoft.com/v1.0/users/frank@temponia.onmicrosoft.com/calendarview?startDateTime=#{start_date.to_s}&endDateTime=#{end_date.to_s}

I get this error message:

Access is denied. Check credentials and try again.

According to the documentation: https://graph.microsoft.io/en-us/docs/authorization/permission_scopes

Calendars.Read: Read calendars in all mailboxes: Allows the app to read events of all calendars without a signed-in user.

The scope I got back together with the access token was this: "calendars.read user.read.all" so it got accepted.

What am I missing here?

回答1:

We are working to support the scenario you are requesting (Accessing other users' calendars) but the feature hasn't shipped yet. Stay tuned ...

UPDATE: Please take a look at using client credential flow. The blog post https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow/ explains how to do this for Outlook API endpoint. But you should be able to follow the instructions for Microsoft Graph as well.

The app will require an admin to consent, and then can access calendar of any user in the organization, as long as their mailbox is in Office 365.