Read the complete article on how to create, update and delete Google Calendar in C#: https://blog.aspose.com/2022/04/10/create-update-or-delete-google-calendar-in-csharp-net/
Last active
May 10, 2022 15:18
-
-
Save aspose-com-gists/14d2e416098408b95b73aff572531e84 to your computer and use it in GitHub Desktop.
Create, Update or Delete Google Calendar in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize Google user | |
GoogleUser User = new GoogleUser("user", "email address", "password", "clientId", "client secret"); | |
string accessToken; | |
string refreshToken; | |
// Get access token | |
GoogleOAuthHelper.GetAccessToken(User, out accessToken, out refreshToken); | |
// Get instance of Gmail client | |
using (IGmailClient client = GmailClient.GetInstance(accessToken, User.EMail)) | |
{ | |
// Insert and get calendar | |
Aspose.Email.Clients.Google.Calendar calendar = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "America/Los_Angeles"); | |
// Insert calendar and retrieve id | |
string id = client.CreateCalendar(calendar); | |
Aspose.Email.Clients.Google.Calendar cal = client.FetchCalendar(id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get instance of Gmail client | |
using (IGmailClient client = GmailClient.GetInstance(accessToken, User.EMail)) | |
{ | |
// Access and delete calendar with summary starting from "Calendar summary - " | |
string summary = "Calendar summary - "; | |
// Get calendars list | |
ExtendedCalendar[] lst0 = client.ListCalendars(); | |
foreach (ExtendedCalendar extCal in lst0) | |
{ | |
// Delete selected calendars | |
if (extCal.Summary.StartsWith(summary)) | |
client.DeleteCalendar(extCal.Id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get instance of Gmail client | |
using (IGmailClient client = GmailClient.GetInstance(accessToken, User.EMail)) | |
{ | |
string id = "<<calendar ID>>"; | |
// Fetch calendar | |
Aspose.Email.Clients.Google.Calendar cal = client.FetchCalendar(id); | |
// Change information in the fetched calendar and update calendar | |
cal.Description = "Description - " + Guid.NewGuid().ToString(); | |
cal.Location = "Location - " + Guid.NewGuid().ToString(); | |
// Update calendar | |
client.UpdateCalendar(cal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment