DataFlex 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


Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vOauth2
    Handle hoOauth2
    Variant vSbReq
    Handle hoSbReq
    Variant vSbJson
    Handle hoSbJson
    Handle hoJson
    String sKind
    String sEtag
    String sId
    String sStatus
    String sHtmlLink
    String sCreated
    String sUpdated
    String sSummary
    String sDescription
    String sLocation
    String sCreatorEmail
    Boolean iCreatorSelf
    String sOrganizerEmail
    String sOrganizerDisplayName
    String sStartDateTime
    String sEndDateTime
    String sICalUID
    Integer iSequence
    String sHangoutLink
    Boolean iRemindersUseDefault
    Integer i
    Integer iCount_i
    String sEmail
    String sResponseStatus
    Boolean iSelf
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //   Provide a previously obtained OAuth2 access token.
    Get Create (RefClass(cComChilkatOAuth2)) To hoOauth2
    If (Not(IsComObjectCreated(hoOauth2))) Begin
        Send CreateComObject of hoOauth2
    End
    Set ComAccessToken Of hoOauth2 To "OAUTH2_ACCESS_TOKEN"
    Get pvComObject of hoOauth2 to vOauth2
    Get ComSetAuthOAuth2 Of hoRest vOauth2 To iSuccess

    Get ComConnect Of hoRest "www.googleapis.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddQueryParam Of hoRest "destination" "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbReq
    If (Not(IsComObjectCreated(hoSbReq))) Begin
        Send CreateComObject of hoSbReq
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
    If (Not(IsComObjectCreated(hoSbJson))) Begin
        Send CreateComObject of hoSbJson
    End
    Get pvComObject of hoSbReq to vSbReq
    Get pvComObject of hoSbJson to vSbJson
    Get ComFullRequestSb Of hoRest "POST" "/calendar/v3/calendars/support@chilkatcloud.com/events/35ocdnnjofbtfs6c602uqvdg9u/move" vSbReq vSbJson To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "Received error response code: " iTemp1
        Showln "Response body:"
        Get ComGetAsString Of hoSbJson To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComLoadSb Of hoJson vSbJson To iSuccess

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

    Get ComStringOf Of hoJson "kind" To sKind
    Get ComStringOf Of hoJson "etag" To sEtag
    Get ComStringOf Of hoJson "id" To sId
    Get ComStringOf Of hoJson "status" To sStatus
    Get ComStringOf Of hoJson "htmlLink" To sHtmlLink
    Get ComStringOf Of hoJson "created" To sCreated
    Get ComStringOf Of hoJson "updated" To sUpdated
    Get ComStringOf Of hoJson "summary" To sSummary
    Get ComStringOf Of hoJson "description" To sDescription
    Get ComStringOf Of hoJson "location" To sLocation
    Get ComStringOf Of hoJson "creator.email" To sCreatorEmail
    Get ComBoolOf Of hoJson "creator.self" To iCreatorSelf
    Get ComStringOf Of hoJson "organizer.email" To sOrganizerEmail
    Get ComStringOf Of hoJson "organizer.displayName" To sOrganizerDisplayName
    Get ComStringOf Of hoJson "start.dateTime" To sStartDateTime
    Get ComStringOf Of hoJson "end.dateTime" To sEndDateTime
    Get ComStringOf Of hoJson "iCalUID" To sICalUID
    Get ComIntOf Of hoJson "sequence" To iSequence
    Get ComStringOf Of hoJson "hangoutLink" To sHangoutLink
    Get ComBoolOf Of hoJson "reminders.useDefault" To iRemindersUseDefault
    Move 0 To i
    Get ComSizeOfArray Of hoJson "attendees" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJson To i
        Get ComStringOf Of hoJson "attendees[i].email" To sEmail
        Get ComStringOf Of hoJson "attendees[i].responseStatus" To sResponseStatus
        Get ComBoolOf Of hoJson "attendees[i].self" To iSelf
        Move i + 1 To i
    Loop

    Showln "Example Completed."


End_Procedure

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