Tcl 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



load ./chilkat.dll

set rest [new_CkRest]

#   Provide a previously obtained OAuth2 access token.
set oauth2 [new_CkOAuth2]

CkOAuth2_put_AccessToken $oauth2 "OAUTH2_ACCESS_TOKEN"
CkRest_SetAuthOAuth2 $rest $oauth2

set success [CkRest_Connect $rest "www.googleapis.com" 443 1 1]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    exit
}

set sbJson [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/calendar/v3/users/me/calendarList/support@chilkatcloud.com" $sbJson]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    delete_CkStringBuilder $sbJson
    exit
}

if {[expr [CkRest_ResponseStatusCode $rest] != 200]} then {
    puts "Received error response code: [CkRest_ResponseStatusCode $rest]"
    puts "Response body:"
    puts [CkStringBuilder_getAsString $sbJson]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    delete_CkStringBuilder $sbJson
    exit
}

set json [new_CkJsonObject]

CkJsonObject_LoadSb $json $sbJson

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

set kind [CkJsonObject_stringOf $json "kind"]
set etag [CkJsonObject_stringOf $json "etag"]
set id [CkJsonObject_stringOf $json "id"]
set summary [CkJsonObject_stringOf $json "summary"]
set timeZone [CkJsonObject_stringOf $json "timeZone"]
set colorId [CkJsonObject_stringOf $json "colorId"]
set backgroundColor [CkJsonObject_stringOf $json "backgroundColor"]
set foregroundColor [CkJsonObject_stringOf $json "foregroundColor"]
set selected [CkJsonObject_BoolOf $json "selected"]
set accessRole [CkJsonObject_stringOf $json "accessRole"]
set primary [CkJsonObject_BoolOf $json "primary"]
set i 0
set count_i [CkJsonObject_SizeOfArray $json "defaultReminders"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $json $i
    set method [CkJsonObject_stringOf $json "defaultReminders[i].method"]
    set minutes [CkJsonObject_IntOf $json "defaultReminders[i].minutes"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $json "notificationSettings.notifications"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $json $i
    set type [CkJsonObject_stringOf $json "notificationSettings.notifications[i].type"]
    set method [CkJsonObject_stringOf $json "notificationSettings.notifications[i].method"]
    set i [expr $i + 1]
}

puts "Example Completed."

delete_CkRest $rest
delete_CkOAuth2 $oauth2
delete_CkStringBuilder $sbJson
delete_CkJsonObject $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
}