Ballerina makes it easy to use and tape together different API to create mashup applications and services. This example explores how ballerina can be used to invoke the Google Calendar API to create events that can work as a simple task reminder.
In order access Google API, you must create an application in the developer console, subscribe to the API you wish to use(in this case the calendar API) and generate Oauth credentials which can then be utilized to create an API key with the scopes needed for the API. Conversely, you could use the google playground application to generate an API key to try out the example. To generate an API key this way,
- Select the calendar API with “https://www.googleapis.com/auth/calendar” (this scope is needed to create new calendar events) from the drop down found in step 1.
- Authorize API to generate an Authorization code along with an access token and a refresh token.
Execute the program passing in the following information in the order specified.
- Access token
- Event end date time in rfc3339 format(look to the example execution found below)
- Event start date time in rfc3339 format.
- Description for the event
- Event title.
ballerina run main calendarAPI/sample/CalendarEventCreator.bal "ya29.XXXXXXXXOEyIODzSIvcnH4xkGCZBjPaRNJTzobPnLOo8a-5fzOnUILeFryHvbIVr8PX_DCFksmZf7ek3fFbRxvBVrB3K9wEQIwGbwXCD9_yJYy8w9EHdXXXXXXXX" "2017-06-02T12:30:00+07:00" "2017-06-02T12:10:00+07:00" "yet another google calendar API test" "test one two"
A new google calendar event will get created based on the values passed in and a pop up reminder will be displayed 15 mins prior to the starting time.
Note: this example was written for ballerina 0.86 and it may not work with other versions.