Thursday, May 2, 2024
HomeC#Easy Google Calendar Occasions Synchronization in .NET MAUI Scheduler

Easy Google Calendar Occasions Synchronization in .NET MAUI Scheduler


Syncfusion .NET MAUI Scheduler encompasses all scheduling functionalities for managing skilled and private appointments.

On this weblog, we’ll see the best way to simply synchronize Google Calendar occasions with the Syncfusion .NET MAUI Scheduler management.

Notice: Earlier than continuing, please learn the Getting Began with .NET MAUI Scheduler documentation.

Let’s get began!

Join Google Cloud service

You need to use the Google Calendar API to attach with Google Calendar programmatically in your .NET MAUI app.

Comply with these steps to create a challenge in Google Cloud and allow Google Calendar API.

Step 1: Log in to the Google Cloud console

First, log in to the Google Cloud console.

Step 2: Create a brand new challenge

Create a brand new challenge by clicking Choose a Challenge –> New Challenge.

Create new .NET MAUI project on Google Cloud console

Now, give the challenge a reputation after which click on Create.Name the Created Project on Google Cloud

Step 3: Allow the Google Calendar API

Within the navigation menu, select APIs & Companies> Library.choose APIs & Services and then Library

Now, seek for the Google Calendar API within the library menu. Click on on it, then click on the Allow button to allow the Calendar API to your challenge.Enable the Google Calendar API

Step 4: Create API key credentials

After enabling the Google Calendar API, click on the APIs & Companies tab and navigate to the Credentials choice from the menu.

Now, click on the Create credentials button. Choose the created challenge, choose the API Key choice, and replica the API key.Create the API key credentials

You’ve got now created your Google Calendar API key, which you should use in your .NET MAUI app to authenticate with the Google Calendar API service.

Step 5: Set up the required NuGet package deal to make use of the Google Calendar service

In your .NET MAUI challenge, use the NuGet Bundle Supervisor to put in the Google.Apis.Calendar.v3 package deal.

Seek advice from the next code instance to make the most of the Google Calendar API key from the Google Cloud service.

// Initialize the Google Calendar service with the API key             
CalendarService service = new Calendar-Service(new BaseClientService.Initializer()
{
       ApiKey = "Use the API key of your created challenge",
       ApplicationName = "Use the title of your created challenge"
});

Fetch Google Calendar occasions

As soon as the Google Calendar API is enabled, you should use the CalendarService to entry occasions by utilizing the Calendar ID of your Google Calendar. To take action, comply with these steps:

  1. Navigate to the Google Calendar. Click on the Settings icon and choose Settings from the dropdown.
    Google Calendar
    Google Calendar
  2. Within the settings, find the ID of your Calendar, as proven within the following picture.
    Google Calendar setting
    Google Calendar setting
  3. Seek advice from the next code instance to see the best way to use the Calendar ID and fetch occasions from Google Calendar.
    string calendarId = "Use Google Calendar Id";
    
    // Outline a DateTime vary to retrieve occasions
    DateTime startDate = DateTime.Now;
    DateTime endDate = DateTime.Now.AddDays(90);
    
    // Outline the request to retrieve occasions
    EventsResource.ListRequest request = service.Occasions.Listing(calendarId);
    request.TimeMin = startDate;
    request.TimeMax = endDate;
    request.ShowDeleted = false;
    
    // Execute the calendar service request and retrieve occasions
    Occasions occasions = request.Execute();

Synchronizing Google Calendar occasions with .NET MAUI Scheduler

Subsequent, we’ll take a look at the best way to load the Google Calendar occasions within the Syncfusion .NET MAUI Scheduler management.

Step 1: Register the handler for Syncfusion Core

Register the handler for Syncfusion Core within the MauiProgram.cs file.

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
        builder.ConfigureSyncfusionCore();
}

Step 2: Create an appointment mannequin class

Create an Appointment information mannequin class that encapsulates the essential appointment particulars. This class might be used to create appointments within the .NET MAUI Scheduler.

Seek advice from the next code instance.

Appointment.cs

public class Appointment 
{
     /// <abstract>
     /// Will get or units the worth to show the beginning date.
     /// </abstract>
     public DateTime From { get; set; }
    
     /// <abstract>
     /// Will get or units the worth to show the tip date.
     /// </abstract>
     public DateTime To { get; set; }

     /// <abstract>
     /// Will get or units the worth to show the topic.
     /// </abstract>
     public string EventName { get; set; }

     /// <abstract>
     /// Will get or units the appointment background shade.
     /// </abstract>
     public Brush Background { get; set; } 
}

Step 3: Create the Scheduler appointments from Google Calendar

Let’s create the Scheduler appointments from the Google Calendar occasions.

Seek advice from the next code instance to retrieve Google Calendar occasions.

SchedulerViewModel.cs

public ObservableCollection<Appointment> Appointments { get; set; } = new ObservableCollection<Appointment>();
 
  
// Execute the calendar service request and retrieve occasions
Occasions occasions = request.Execute();
foreach (Occasion appointment in occasions.Objects)
{
    Appointments.Add(new Appointment()
    {
         EventName = appointment.Abstract,
         From = Convert.ToDateTime(appointment.Begin.Date),
         To = Convert.ToDateTime(appointment.Finish.Date),
    });
}

Step 4: Bind appointments to the Scheduler

Initialize the .NET MAUI Scheduler management.

MainPage.xaml

xmlns:scheduler="clr-namespace:Syncfusion.Maui.Scheduler;meeting=Syncfusion.Maui.Scheduler"

<scheduler:SfScheduler/>

Lastly, bind the customized Appointments to the Scheduler’s AppointmentsSource utilizing the appointment mapping characteristic.

Seek advice from the next code instance to bind the AppointmentsSource property from the SchedulerViewModel class.

MainPage.xaml

<scheduler:SfScheduler View="Month" AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth,Agenda" AppointmentsSource="{Binding Appointments}">
 <scheduler:SfScheduler.AppointmentMapping>
  <scheduler:SchedulerAppointmentMapping Topic="EventName" StartTime="From" Background="Background" EndTime="To"/>
 </scheduler:SfScheduler.AppointmentMapping>
 <scheduler:SfScheduler.BindingContext>
  <native:SchedulerViewModel/>
 </scheduler:SfScheduler.BindingContext>
</scheduler:SfScheduler>

Seek advice from the next photographs.

Events in Google Calendar
Occasions in Google Calendar
Synchronizing Google Calendar Events in the Syncfusion .NET MAUI Scheduler
Synchronizing Google Calendar Occasions within the Syncfusion .NET MAUI Scheduler

GitHub reference

For extra particulars, check with Synchronizing Google Calendar occasions in .NET MAUI Scheduler on GitHub.

Conclusion

Thanks for studying! This weblog taught us the best way to synchronize Google Calendar occasions within the Syncfusion .NET MAUI Scheduler management. Do this your self and go away your suggestions within the feedback part beneath.

For present Syncfusion clients, the most recent model of Important Studio is out there from the license and downloads web page. If you’re not a buyer, strive our 30-day free trial to take a look at these new options.

It’s also possible to contact us by our assist discussion boardassist portal, or suggestions portal. We’re all the time blissful to help you!

Associated blogs

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments