Search code examples
c#google-apigoogle-oauthgoogle-calendar-apimicrosoft365

C# Google Calendar API - Credentials/Microsoft Account


Well, my problem is that I have to register the calendar in my personal google account which isn't a problem but...

When creating a new event, my personal e-mail will display there as an Organizer and will put the event in my personal calendar as well.

In the company, we use Microsoft 365 accounts which would be the best to use. I mean, is there a way to solve this?

The best way to solve this is that when I create the event, I give it a string (which is a microsoft email) and that should be the organizer (in spite of the fact that it's not a google account). The main problem is that I have to pre register the ClientID in the application to run the whole process. I use the following right now with google account:

public static CalendarService getCalendarService
{
   get
   {
      var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret },
      new[] { CalendarService.Scope.Calendar }, "user", CancellationToken.None).Result;
      return new CalendarService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = "Deadline calendar" });
    }
}

Solution

  • The problem you have is that the owner of an event is the one who created it. The one who created it is the currently authenticated user. Basically what ever account you logged in with and consented to the access and ran your application from.

    You would need to covert the Microsoft 365 email account to a google account, then login with that account, create events with that account and then it will be the owner.