Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 10, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/14d2e416098408b95b73aff572531e84 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/14d2e416098408b95b73aff572531e84 to your computer and use it in GitHub Desktop.
Create, Update or Delete Google Calendar in C# .NET
// 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);
}
// 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);
}
}
// 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