Module googleapis.calendar.listener
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_googleapis.calendar_2.1.1.png)
ballerinax/googleapis.calendar.listener Ballerina library
2.1.1
Overview
The Google Calendar Connector listener provides you to capture the events created, updated and deleted in the calendar.
This module supports Google Calendar API V3.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
- Create a Google account
- Register the callback URL domain.
- Obtain tokens - Follow the steps here to obtain tokens.
Quickstart
To use the Google Calendar listener connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
Import the ballerinax/googleapis.calendar
and ballerinax/googleapis.calendar.'listener
modules into the Ballerina project.
import ballerinax/googleapis.calendar; import ballerinax/googleapis.calendar.'listener as listen;
Step 2: Create a new listener instance
Create a calendar:ConnectionConfig
with the OAuth2.0 tokens obtained and initialize the connector with it.
int port = 4567; string calendarId = "primary"; string address = "<call_back url + "/calendar/events">"; calendar:ConnectionConfig config = { auth: { clientId: <CLIENT_ID>, clientSecret: <CLIENT_SECRET> refreshToken: <REFRESH_TOKEN>, refreshUrl: <REFRESH_URL>, } }; listener listen:Listener googleListener = new (port, config, calendarId, address);
Step 3: Define Ballerina service with the listener
- Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to create a listener for new event occurred in the calendar using the connector.
service /calendar on googleListener { remote function onNewEvent(calendar:Event event) returns error? { // } }
- Use
bal run
command to compile and run the Ballerina program.