Delphi DLL Google Calendar: Get Calendar

Back to Index

Returns an entry on the user's calendar list.
This example gets the calendar having the ID = "support@chilkatcloud.com".

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/get


var
rest: HCkRest;
success: Boolean;
oauth2: HCkOAuth2;
sbJson: HCkStringBuilder;
json: HCkJsonObject;
kind: PWideChar;
etag: PWideChar;
id: PWideChar;
summary: PWideChar;
timeZone: PWideChar;
colorId: PWideChar;
backgroundColor: PWideChar;
foregroundColor: PWideChar;
selected: Boolean;
accessRole: PWideChar;
primary: Boolean;
i: Integer;
count_i: Integer;
method: PWideChar;
minutes: Integer;
type: PWideChar;

begin
rest := CkRest_Create();

//   Provide a previously obtained OAuth2 access token.
oauth2 := CkOAuth2_Create();
CkOAuth2_putAccessToken(oauth2,'OAUTH2_ACCESS_TOKEN');
CkRest_SetAuthOAuth2(rest,oauth2);

success := CkRest_Connect(rest,'www.googleapis.com',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

sbJson := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/calendar/v3/users/me/calendarList/support@chilkatcloud.com',sbJson);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

if (CkRest_getResponseStatusCode(rest) <> 200) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
    Exit;
  end;

json := CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);

//  The following code parses the JSON response.
//  A sample JSON response is shown below the sample code.

kind := CkJsonObject__stringOf(json,'kind');
etag := CkJsonObject__stringOf(json,'etag');
id := CkJsonObject__stringOf(json,'id');
summary := CkJsonObject__stringOf(json,'summary');
timeZone := CkJsonObject__stringOf(json,'timeZone');
colorId := CkJsonObject__stringOf(json,'colorId');
backgroundColor := CkJsonObject__stringOf(json,'backgroundColor');
foregroundColor := CkJsonObject__stringOf(json,'foregroundColor');
selected := CkJsonObject_BoolOf(json,'selected');
accessRole := CkJsonObject__stringOf(json,'accessRole');
primary := CkJsonObject_BoolOf(json,'primary');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'defaultReminders');
while i < count_i do
  begin
CkJsonObject_putI(json,i);
    method := CkJsonObject__stringOf(json,'defaultReminders[i].method');
    minutes := CkJsonObject_IntOf(json,'defaultReminders[i].minutes');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(json,'notificationSettings.notifications');
while i < count_i do
  begin
CkJsonObject_putI(json,i);
    type := CkJsonObject__stringOf(json,'notificationSettings.notifications[i].type');
    method := CkJsonObject__stringOf(json,'notificationSettings.notifications[i].method');
    i := i + 1;
  end;

Memo1.Lines.Add('Example Completed.');

CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);

Sample JSON Response Body

{
  "kind": "calendar#calendarListEntry",
  "etag": "\"1465249947472000\"",
  "id": "support@chilkatcloud.com",
  "summary": "support@chilkatcloud.com",
  "timeZone": "America/Chicago",
  "colorId": "14",
  "backgroundColor": "#9fe1e7",
  "foregroundColor": "#000000",
  "selected": true,
  "accessRole": "owner",
  "defaultReminders": [
    {
      "method": "popup",
      "minutes": 10
    }
  ],
  "notificationSettings": {
    "notifications": [
      {
        "type": "eventCreation",
        "method": "email"
      },
      {
        "type": "eventChange",
        "method": "email"
      },
      {
        "type": "eventCancellation",
        "method": "email"
      },
      {
        "type": "eventResponse",
        "method": "email"
      }
    ]
  },
  "primary": true
}