Create a Windows service project to Add Events using Microsoft Graph

Udal Bharti 0 Reputation points
2023-08-28T13:13:57.2266667+00:00

Dear Members,

I am developing a Windows service project which will create events using Microsoft Graph API.
I chosen window service as my program will pull events from database and push in Outlook Calendar using Graph API.

At first in azure portal i have registered my application as Mobile and desktop app and give permission. I have delegated permissions in azure for Calendar.ReadWrite.
I am successfully getting token using this below code where i used this as scope

   var scopes = new string[] { "https://graph.microsoft.com/.default" };
IConfidentialClientApplication app;

            app = ConfidentialClientApplicationBuilder.Create(clientId)
                .WithClientSecret(clientSecret)
                .WithTenantId(tenantId)
                .Build();

            AuthenticationResult result = null;
            try
            {
                result = await app.AcquireTokenForClient(scopes)
                    .ExecuteAsync();

               

            }
            catch (ServiceException e)
            {
            }

            return result.AccessToken;

then i am using "https://graph.microsoft.com/v1.0/users/"+ UserId +"/events"; to create the events but its not working at all

**Error : Access is denied. Check credentials and try again
**
Thanks

Udal

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,518 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,419 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.