ezG
ezG

Reputation: 421

How do I access Events in a calendar other than my own using Graph API and C#

I know how to accomplish this using MS Graph Explorer. However, I need to get this done in C# code.

The code below is from Microsoft. I would like to be able to query/update a random user (yes, I have permissions to these user calendars).

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // Get the Graph client from the provider
            var graphClient = ProviderManager.Instance.GlobalProvider.Graph;

            try
            {
                // Get the events
                var events = await graphClient.Me.Events.Request()
                    .Select("subject,organizer,start,end")
                    .OrderBy("createdDateTime DESC")
                    .GetAsync();

               
                EventList.ItemsSource = events.CurrentPage.ToList();
            }
            catch (Microsoft.Graph.ServiceException ex)
            {
                ShowNotification($"Exception getting events: {ex.Message}");
            }

            base.OnNavigatedTo(e);
        }

Upvotes: 2

Views: 1157

Answers (1)

Homungus
Homungus

Reputation: 1114

To get the events of other users than yourself use this statement:

var events = await graphClient.Users[{userID}].Events.Request()
    .Select("subject,organizer,start,end")
    .OrderBy("createdDateTime DESC")
    .GetAsync();

Upvotes: 1

Related Questions