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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbReq
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL lcEtag
LOCAL lcId
LOCAL lcStatus
LOCAL lcHtmlLink
LOCAL lcCreated
LOCAL lcUpdated
LOCAL lcSummary
LOCAL lcDescription
LOCAL lcLocation
LOCAL lcCreatorEmail
LOCAL lnCreatorSelf
LOCAL lcOrganizerEmail
LOCAL lcOrganizerDisplayName
LOCAL lcStartDateTime
LOCAL lcEndDateTime
LOCAL lcICalUID
LOCAL lnSequence
LOCAL lcHangoutLink
LOCAL lnRemindersUseDefault
LOCAL i
LOCAL lnCount_i
LOCAL lcEmail
LOCAL lcResponseStatus
LOCAL lnSelf

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

loRest.AddQueryParam("destination","chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com")

loSbReq = CreateObject('Chilkat_9_5_0.StringBuilder')

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/calendar/v3/calendars/support@chilkatcloud.com/events/35ocdnnjofbtfs6c602uqvdg9u/move",loSbReq,loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbReq
    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 loSbReq
    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")
lcId = loJson.StringOf("id")
lcStatus = loJson.StringOf("status")
lcHtmlLink = loJson.StringOf("htmlLink")
lcCreated = loJson.StringOf("created")
lcUpdated = loJson.StringOf("updated")
lcSummary = loJson.StringOf("summary")
lcDescription = loJson.StringOf("description")
lcLocation = loJson.StringOf("location")
lcCreatorEmail = loJson.StringOf("creator.email")
lnCreatorSelf = loJson.BoolOf("creator.self")
lcOrganizerEmail = loJson.StringOf("organizer.email")
lcOrganizerDisplayName = loJson.StringOf("organizer.displayName")
lcStartDateTime = loJson.StringOf("start.dateTime")
lcEndDateTime = loJson.StringOf("end.dateTime")
lcICalUID = loJson.StringOf("iCalUID")
lnSequence = loJson.IntOf("sequence")
lcHangoutLink = loJson.StringOf("hangoutLink")
lnRemindersUseDefault = loJson.BoolOf("reminders.useDefault")
i = 0
lnCount_i = loJson.SizeOfArray("attendees")
DO WHILE i < lnCount_i
    loJson.I = i
    lcEmail = loJson.StringOf("attendees[i].email")
    lcResponseStatus = loJson.StringOf("attendees[i].responseStatus")
    lnSelf = loJson.BoolOf("attendees[i].self")
    i = i + 1
ENDDO

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbReq
RELEASE loSbJson
RELEASE loJson

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
  }
}