DataFlex
DataFlex
List Google Calendars
See more Google Calendar Examples
Demonstrates how to list the Google Calendars for an account.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Token Handle hoJsonToken
Handle hoHttp
String sJsonResponse
Handle hoJson
Integer iNumCalendars
Integer i
Integer iNumSettings
Integer j
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// This example uses a previously obtained access token having permission for the
// Google Calendar scope.
// In this example, Get Google Calendar OAuth2 Access Token, the access
// token was saved to a JSON file. This example fetches the access token from the file..
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
If (Not(IsComObjectCreated(hoJsonToken))) Begin
Send CreateComObject of hoJsonToken
End
Get ComLoadFile Of hoJsonToken "qa_data/tokens/googleCalendar.json" To iSuccess
Get ComHasMember Of hoJsonToken "access_token" To bTemp1
If (bTemp1 = False) Begin
Showln "No access token found."
Procedure_Return
End
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Get ComStringOf Of hoJsonToken "access_token" To sTemp1
Set ComAuthToken Of hoHttp To sTemp1
Get ComQuickGetStr Of hoHttp "https://www.googleapis.com/calendar/v3/users/me/calendarList" To sJsonResponse
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sJsonResponse
Showln "-----------------------------"
// This is a sample JSON response:
// (Sample code to iterate over the JSON response is shown below.)
// {
// "kind": "calendar#calendarList",
// "etag": "\"p32cfpufit76da0g\"",
// "nextSyncToken": "CJj8-fLpzNUCEhhzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20=",
// "items": [
// {
// "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
// },
// {
// "kind": "calendar#calendarListEntry",
// "etag": "\"1502373382732000\"",
// "id": "#contacts@group.v.calendar.google.com",
// "summary": "Contacts",
// "timeZone": "America/Chicago",
// "colorId": "13",
// "backgroundColor": "#92e1c0",
// "foregroundColor": "#000000",
// "selected": true,
// "accessRole": "reader",
// "defaultReminders": []
// },
// {
// "kind": "calendar#calendarListEntry",
// "etag": "\"1502373376447000\"",
// "id": "en.usa#holiday@group.v.calendar.google.com",
// "summary": "Holidays in United States",
// "timeZone": "America/Chicago",
// "colorId": "8",
// "backgroundColor": "#16a765",
// "foregroundColor": "#000000",
// "selected": true,
// "accessRole": "reader",
// "defaultReminders": []
// }
// ]
// }
//
// Iterate over the JSON response..
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComLoad Of hoJson sJsonResponse To iSuccess
Get ComSizeOfArray Of hoJson "items" To iNumCalendars
Move 0 To i
While (i < iNumCalendars)
Showln "--- " i " ---"
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "items[i].kind" To sTemp1
Showln "kind: " sTemp1
Get ComStringOf Of hoJson "items[i].id" To sTemp1
Showln "id: " sTemp1
// Examine the notification settings, if any..
Get ComSizeOfArray Of hoJson "items[i].notificationSettings.notifications" To iNumSettings
If (iNumSettings > 0) Begin
Move 0 To j
While (j < iNumSettings)
Set ComJ Of hoJson To j
Get ComStringOf Of hoJson "items[i].notificationSettings.notifications[j].type" To sTemp1
Showln "Notification Type: " sTemp1
Get ComStringOf Of hoJson "items[i].notificationSettings.notifications[j].method" To sTemp1
Showln "Notification Method: " sTemp1
Move (j + 1) To j
Loop
End
Move (i + 1) To i
Loop
End_Procedure