Visual FoxPro 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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL lcEtag
LOCAL lcNextSyncToken
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcSummary
LOCAL lcTimeZone
LOCAL lcColorId
LOCAL lcBackgroundColor
LOCAL lcForegroundColor
LOCAL lnSelected
LOCAL lcAccessRole
LOCAL lnPrimary
LOCAL j
LOCAL lnCount_j
LOCAL lcMethod
LOCAL lnMinutes
LOCAL lcType

loRest = CreateObject('Chilkat_9_5_0.Rest')

*   Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)

lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    CANCEL
ENDIF

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/calendar/v3/users/me/calendarList",loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.LoadSb(loSbJson)

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

lcKind = loJson.StringOf("kind")
lcEtag = loJson.StringOf("etag")
lcNextSyncToken = loJson.StringOf("nextSyncToken")
i = 0
lnCount_i = loJson.SizeOfArray("items")
DO WHILE i < lnCount_i
    loJson.I = i
    lcKind = loJson.StringOf("items[i].kind")
    lcEtag = loJson.StringOf("items[i].etag")
    lcId = loJson.StringOf("items[i].id")
    lcSummary = loJson.StringOf("items[i].summary")
    lcTimeZone = loJson.StringOf("items[i].timeZone")
    lcColorId = loJson.StringOf("items[i].colorId")
    lcBackgroundColor = loJson.StringOf("items[i].backgroundColor")
    lcForegroundColor = loJson.StringOf("items[i].foregroundColor")
    lnSelected = loJson.BoolOf("items[i].selected")
    lcAccessRole = loJson.StringOf("items[i].accessRole")
    lnPrimary = loJson.BoolOf("items[i].primary")
    j = 0
    lnCount_j = loJson.SizeOfArray("items[i].defaultReminders")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcMethod = loJson.StringOf("items[i].defaultReminders[j].method")
        lnMinutes = loJson.IntOf("items[i].defaultReminders[j].minutes")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("items[i].notificationSettings.notifications")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcType = loJson.StringOf("items[i].notificationSettings.notifications[j].type")
        lcMethod = loJson.StringOf("items[i].notificationSettings.notifications[j].method")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbJson
RELEASE loJson

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": []
  }
 ]
}