PowerBuilder Google Calendar: List Calendars

Back to Index

Returns entries on the user's calendar list.

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


integer li_rc
oleobject loo_Rest
integer li_Success
oleobject loo_Oauth2
oleobject loo_SbJson
oleobject loo_Json
string ls_Kind
string ls_Etag
string ls_NextSyncToken
integer i
integer li_Count_i
string ls_Id
string ls_Summary
string ls_TimeZone
string ls_ColorId
string ls_BackgroundColor
string ls_ForegroundColor
integer li_Selected
string ls_AccessRole
integer li_Primary
integer j
integer li_Count_j
string ls_Method
integer li_Minutes
string ls_Type

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//   Provide a previously obtained OAuth2 access token.
loo_Oauth2 = create oleobject
li_rc = loo_Oauth2.ConnectToNewObject("Chilkat_9_5_0.OAuth2")

loo_Oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loo_Rest.SetAuthOAuth2(loo_Oauth2)

li_Success = loo_Rest.Connect("www.googleapis.com",443,1,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    return
end if

loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/calendar/v3/users/me/calendarList",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response body:"
    Write-Debug loo_SbJson.GetAsString()
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.LoadSb(loo_SbJson)

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

ls_Kind = loo_Json.StringOf("kind")
ls_Etag = loo_Json.StringOf("etag")
ls_NextSyncToken = loo_Json.StringOf("nextSyncToken")
i = 0
li_Count_i = loo_Json.SizeOfArray("items")
do while i < li_Count_i
    loo_Json.I = i
    ls_Kind = loo_Json.StringOf("items[i].kind")
    ls_Etag = loo_Json.StringOf("items[i].etag")
    ls_Id = loo_Json.StringOf("items[i].id")
    ls_Summary = loo_Json.StringOf("items[i].summary")
    ls_TimeZone = loo_Json.StringOf("items[i].timeZone")
    ls_ColorId = loo_Json.StringOf("items[i].colorId")
    ls_BackgroundColor = loo_Json.StringOf("items[i].backgroundColor")
    ls_ForegroundColor = loo_Json.StringOf("items[i].foregroundColor")
    li_Selected = loo_Json.BoolOf("items[i].selected")
    ls_AccessRole = loo_Json.StringOf("items[i].accessRole")
    li_Primary = loo_Json.BoolOf("items[i].primary")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("items[i].defaultReminders")
    do while j < li_Count_j
        loo_Json.J = j
        ls_Method = loo_Json.StringOf("items[i].defaultReminders[j].method")
        li_Minutes = loo_Json.IntOf("items[i].defaultReminders[j].minutes")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("items[i].notificationSettings.notifications")
    do while j < li_Count_j
        loo_Json.J = j
        ls_Type = loo_Json.StringOf("items[i].notificationSettings.notifications[j].type")
        ls_Method = loo_Json.StringOf("items[i].notificationSettings.notifications[j].method")
        j = j + 1
    loop
    i = i + 1
loop

Write-Debug "Example Completed."


destroy loo_Rest
destroy loo_Oauth2
destroy loo_SbJson
destroy loo_Json

Sample JSON Response Body

{
 "kind": "calendar#calendarList",
 "etag": "\"p33gdfl6bualde0g\"",
 "nextSyncToken": "CODX1MvyqtcCEhhzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20=",
 "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": []
  }
 ]
}