cdp
cdp

Reputation: 19

Office365 API access for all network users' calendars using c#

So my main objective is to update network user's outlook calendar from sql server data using office365 api every few minutes. I am stuck at how to get access for other user's outlook calendar? Looked at below link but didnt asnwser much...do i need azure subscription in order to do this? If someone can point me to right direction, that would be great

https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks

Upvotes: 0

Views: 992

Answers (1)

Jeffrey Chen
Jeffrey Chen

Reputation: 4690

I am stuck at how to get access for other user's outlook calendar?

In this case, you can consider using the application permission.

In Azure AD:

  1. register a Web Application in your Azure AD.
  2. add “Read and write calendars in all mail boxes” permission enter image description here
  3. generate the application secret key

In your application, call Office 365 Graph API - create events by using application token.

http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_post_events

        var tmgr = new ApplicationTokenManagement();

        var token = tmgr.AcquireToken(Settings.ResourceUrlOfGraph);

        var api = new Graph.GraphCalendarAPI(token);

        JObject body = new JObject
        {
            {"subject", "Create from Office 365 API"},
            {"start", new JObject { { "DateTime", "2016-03-09T00:00:00"}, { "TimeZone", "China Standard Time" } } },
            {"end", new JObject { { "DateTime", "2016-03-10T00:00:00"}, { "TimeZone", "China Standard Time" } } },
            {"isAllDay", true }
        };

        var task = api.CreateEventAsync(body, "[email protected]");

        task.Wait();

You can find the complete sample here.

Upvotes: 0

Related Questions