Tcl Google Calendar: Move Event to Another Calendar

Back to Index

Moves an event to another calendar, i.e. changes an event's organizer.
This example moves event ID="35ocdnnjofbtfs6c602uqvdg9u" from the calendar (ID = "support@chilkatcloud.com") to the calendar (ID = "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com")

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/move



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
}

CkRest_AddQueryParam $rest "destination" "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com"

set sbReq [new_CkStringBuilder]

set sbJson [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/calendar/v3/calendars/support@chilkatcloud.com/events/35ocdnnjofbtfs6c602uqvdg9u/move" $sbReq $sbJson]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    delete_CkStringBuilder $sbReq
    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 $sbReq
    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 status [CkJsonObject_stringOf $json "status"]
set htmlLink [CkJsonObject_stringOf $json "htmlLink"]
set created [CkJsonObject_stringOf $json "created"]
set updated [CkJsonObject_stringOf $json "updated"]
set summary [CkJsonObject_stringOf $json "summary"]
set description [CkJsonObject_stringOf $json "description"]
set location [CkJsonObject_stringOf $json "location"]
set creatorEmail [CkJsonObject_stringOf $json "creator.email"]
set creatorSelf [CkJsonObject_BoolOf $json "creator.self"]
set organizerEmail [CkJsonObject_stringOf $json "organizer.email"]
set organizerDisplayName [CkJsonObject_stringOf $json "organizer.displayName"]
set startDateTime [CkJsonObject_stringOf $json "start.dateTime"]
set endDateTime [CkJsonObject_stringOf $json "end.dateTime"]
set iCalUID [CkJsonObject_stringOf $json "iCalUID"]
set sequence [CkJsonObject_IntOf $json "sequence"]
set hangoutLink [CkJsonObject_stringOf $json "hangoutLink"]
set remindersUseDefault [CkJsonObject_BoolOf $json "reminders.useDefault"]
set i 0
set count_i [CkJsonObject_SizeOfArray $json "attendees"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $json $i
    set email [CkJsonObject_stringOf $json "attendees[i].email"]
    set responseStatus [CkJsonObject_stringOf $json "attendees[i].responseStatus"]
    set self [CkJsonObject_BoolOf $json "attendees[i].self"]
    set i [expr $i + 1]
}

puts "Example Completed."

delete_CkRest $rest
delete_CkOAuth2 $oauth2
delete_CkStringBuilder $sbReq
delete_CkStringBuilder $sbJson
delete_CkJsonObject $json

Sample JSON Response Body

{
  "kind": "calendar#event",
  "etag": "\"3020341523602000\"",
  "id": "35ocdnnjofbtfs6c602uqvdg9u",
  "status": "confirmed",
  "htmlLink": "https://www.google.com/calendar/event?eid=MzVvY2RubmpvZmJ0ZnM2YzYwMnVxdmRnOXUgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
  "created": "2017-11-08T18:25:38.000Z",
  "updated": "2017-11-08T19:52:41.801Z",
  "summary": "QXQC",
  "description": "20th Annual QXQC Gathering",
  "location": "Quigley's Irish Pub, 43 E Jefferson Ave, Naperville, IL 60540, USA",
  "creator": {
    "email": "support@chilkatcloud.com",
    "self": true
  },
  "organizer": {
    "email": "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",
    "displayName": "Party Calendar"
  },
  "start": {
    "dateTime": "2017-11-09T20:00:00-06:00"
  },
  "end": {
    "dateTime": "2017-11-09T23:00:00-06:00"
  },
  "iCalUID": "35ocdnnjofbtfs6c602uqvdg9u@google.com",
  "sequence": 0,
  "attendees": [
    {
      "email": "dean@example.com",
      "responseStatus": "needsAction"
    },
    {
      "email": "support@chilkatcloud.com",
      "self": true,
      "responseStatus": "accepted"
    },
    {
      "email": "ajay@example.com",
      "responseStatus": "needsAction"
    },
    {
      "email": "jim@example.com",
      "responseStatus": "needsAction"
    },
    {
      "email": "gilian@example.com",
      "responseStatus": "needsAction"
    }
  ],
  "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.35ocdnnjofbtfs6c602uqvdg9u",
  "reminders": {
    "useDefault": true
  }
}