Site Map Contact Us Home
E-mail Newsletter
Subscribe to get informed about
Clever Components news.

Your Name:
Your Email:
 
SUBSCRIBE
 
Previous Newsletters
 




Products Articles Downloads Order Support
Customer Portal      

Google Calendar API for Delphi

Google Calendar for Delphi

The Google Calendar API Client Library for Delphi provides functionality common to Google Calendar API, for example Event creation, error handling, authentication, JSON parsing, etc.

The library includes a powerful OAuth 2.0 support with a consistent interface. You can use the Google Calendar API for Delphi to find and view public calendar events as well as to manage private calendars and events on those calendars.

This article describes how to create calendar events programmatically and add them to your users' calendars.

Create Events

The usage of the Google Calendar API for Delphi is simple and is similar to Google Calendar API for .NET and Google Calendar API for Java. The structure and members of classes from Google Calendar API for Delphi helps you to easily migrate an existing .NET or Java code to Delphi.

For creating a Google Calendar event, you need to select the desired calendar ID and call to the Insert method of the Events collection:

var
   insertReq: TEventsInsertRequest;
   event: TEvent;
...
   event := TEvent.Create();
   event.Start := TEventDateTime.Create();
   event.Start.DateTime := Now() + 1;
   event.End_ := TEventDateTime.Create();
   event.End_.DateTime := Now() + 2;
   event.Summary := 'Sample event';

   insertReq := GetService().Events.Insert(calendarId, event);
   try
      event := insertReq.Execute();
   finally
      insertReq.Free();
   end;
...
//use event
...

OAuth authorization

To work with Google Calendar API you need first to create the Calendar Service instance and set up the OAuth credentials. Your application must send an OAuth 2.0 token with any request that accesses private user data. With Google Deverlopers Console you can set up the desired Project Name, Client ID and Client Secret that are necessary to generate OAuth 2.0 credentials for your application. The Calendar Service initialization code may look like the following:

// [Delphi]
function TCalendarServiceTests.GetService: TCalendarService;
var
   credential: TGoogleOAuthCredential;
   initializer: TServiceInitializer;
begin
   if (FService = nil) then
   begin
      credential := TGoogleOAuthCredential.Create();
      initializer := TGoogleApisServiceInitializer.Create(credential, 'CleverComponents Calendar test');
      FService := TCalendarService.Create(initializer);

      credential.ClientID := '421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com';
      credential.ClientSecret := '_4HJyAVUmH_iVrPB8pOJXjR1';
      credential.Scope := 'https://www.googleapis.com/auth/calendar';
   end;
   Result := FService;
end;

Supported compiler versions

Google Calendar API for Delphi can be used in RAD Studio XE3 and later. If you modify the sources and remove all references to the RAD Studio namespaces in the 'uses' sections, you can use the library in RAD Studio 2009, 2010, XE and XE2 as well.

Download source code

The library is distributed under the terms of the GNU Lesser General Public License version 3GNU General Public License

  Name   Download
 Google Calendar API for Delphi Download on GitHub
 Json Serializer Download on GitHub
 Internet Components - Clever Internet Suite Download

The current version of Google API Client Library for Delphi needs for the non-free library Clever Internet Suite. This is a drawback, and we suggest the task of changing the program so that it does the same job without the non-free library. Anyone who thinks of doing substantial further work on the program, first may free it from dependence on the non-free library. The class structure allows you to easily replace the Clever Internet Suite Http and Oauth components with any other third-party free and non-free software.

Please feel free Contact us if you need any assistance.

 

Sergey Shirokov
Clever Components team
www.clevercomponents.com

    Copyright © 2000-2024