Read the complete article on how to create, update and delete Google Calendar in Java: https://blog.aspose.com/2022/05/10/create-update-or-delete-google-calendar-in-java/
Last active
May 10, 2022 07:04
-
-
Save aspose-com-gists/b0078a63655cbe08b7295b671a06d014 to your computer and use it in GitHub Desktop.
Create, Update or Delete Google Calendar in Java
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
OAuthUser user = new OAuthUser(); | |
// Set clientId, clientSecret and email | |
user.clientId = "<<clientID>>"; | |
user.clientSecret = "<<clientSecret>>"; | |
user.email = "<<email>>"; | |
// You have to retrieve AuthorizationCode manually with generated AuthorizationCodeUrl | |
// Set authorizationCode | |
String authorizationCode = "<<authCode>>"; | |
// Copy Code Verifier from the previous step output | |
// Set codeVerifier | |
String codeVerifier = "<<codeVerifier>>"; | |
// Get Refresh Token | |
String refreshToken = GoogleOAuthHelper.getAccessTokenByAuthCode(authorizationCode, codeVerifier, user); | |
user.refreshToken = refreshToken; | |
// Get Access Token | |
String accessToken = GoogleOAuthHelper.getAccessTokenByRefreshToken(user); | |
// Create Gmail client | |
try (IGmailClient client = GmailClient.getInstance(accessToken, user.email)) { | |
// Insert, get and update calendar | |
Calendar calendar = new Calendar("Summary", "Description", "Location", "America/Los_Angeles"); | |
// Insert calendar and Retrieve same calendar using id | |
String id = client.createCalendar(calendar); | |
} |
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
// Create Gmail client | |
try (IGmailClient client = GmailClient.getInstance(accessToken, email)) { | |
// Access and delete calendar with summary starting from "Calendar summary" | |
String summary = "Calendar summary"; | |
// Get calendars list | |
ExtendedCalendar[] lst = client.listCalendars(); | |
for (ExtendedCalendar extCal : lst) { | |
// Delete selected calendars | |
if (extCal.getSummary().startsWith(summary)) | |
client.deleteCalendar(extCal.getId()); | |
} | |
} |
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
// Create Gmail client | |
try (IGmailClient client = GmailClient.getInstance(accessToken, email)) { | |
// Specify calendar ID | |
String id ="<<calendar ID>>" | |
// Fetch calendar | |
Calendar cal = client.fetchCalendar(id); | |
// Change information in the fetched calendar and update calendar | |
cal.setDescription("New Description"); | |
cal.setLocation("New Location"); | |
// Update calendar | |
client.updateCalendar(cal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment