Unicode C 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


#include <C_CkRestW.h>
#include <C_CkOAuth2W.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkOAuth2W oauth2;
    HCkStringBuilderW sbReq;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    const wchar_t *kind;
    const wchar_t *etag;
    const wchar_t *id;
    const wchar_t *status;
    const wchar_t *htmlLink;
    const wchar_t *created;
    const wchar_t *updated;
    const wchar_t *summary;
    const wchar_t *description;
    const wchar_t *location;
    const wchar_t *creatorEmail;
    BOOL creatorSelf;
    const wchar_t *organizerEmail;
    const wchar_t *organizerDisplayName;
    const wchar_t *startDateTime;
    const wchar_t *endDateTime;
    const wchar_t *iCalUID;
    int sequence;
    const wchar_t *hangoutLink;
    BOOL remindersUseDefault;
    int i;
    int count_i;
    const wchar_t *email;
    const wchar_t *responseStatus;
    BOOL self;

    rest = CkRestW_Create();

    //   Provide a previously obtained OAuth2 access token.
    oauth2 = CkOAuth2W_Create();
    CkOAuth2W_putAccessToken(oauth2,L"OAUTH2_ACCESS_TOKEN");
    CkRestW_SetAuthOAuth2(rest,oauth2);

    success = CkRestW_Connect(rest,L"www.googleapis.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        return;
    }

    CkRestW_AddQueryParam(rest,L"destination",L"chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com");

    sbReq = CkStringBuilderW_Create();

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/calendar/v3/calendars/support@chilkatcloud.com/events/35ocdnnjofbtfs6c602uqvdg9u/move",sbReq,sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);

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

    kind = CkJsonObjectW_stringOf(json,L"kind");
    etag = CkJsonObjectW_stringOf(json,L"etag");
    id = CkJsonObjectW_stringOf(json,L"id");
    status = CkJsonObjectW_stringOf(json,L"status");
    htmlLink = CkJsonObjectW_stringOf(json,L"htmlLink");
    created = CkJsonObjectW_stringOf(json,L"created");
    updated = CkJsonObjectW_stringOf(json,L"updated");
    summary = CkJsonObjectW_stringOf(json,L"summary");
    description = CkJsonObjectW_stringOf(json,L"description");
    location = CkJsonObjectW_stringOf(json,L"location");
    creatorEmail = CkJsonObjectW_stringOf(json,L"creator.email");
    creatorSelf = CkJsonObjectW_BoolOf(json,L"creator.self");
    organizerEmail = CkJsonObjectW_stringOf(json,L"organizer.email");
    organizerDisplayName = CkJsonObjectW_stringOf(json,L"organizer.displayName");
    startDateTime = CkJsonObjectW_stringOf(json,L"start.dateTime");
    endDateTime = CkJsonObjectW_stringOf(json,L"end.dateTime");
    iCalUID = CkJsonObjectW_stringOf(json,L"iCalUID");
    sequence = CkJsonObjectW_IntOf(json,L"sequence");
    hangoutLink = CkJsonObjectW_stringOf(json,L"hangoutLink");
    remindersUseDefault = CkJsonObjectW_BoolOf(json,L"reminders.useDefault");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"attendees");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        email = CkJsonObjectW_stringOf(json,L"attendees[i].email");
        responseStatus = CkJsonObjectW_stringOf(json,L"attendees[i].responseStatus");
        self = CkJsonObjectW_BoolOf(json,L"attendees[i].self");
        i = i + 1;
    }

    wprintf(L"Example Completed.\n");


    CkRestW_Dispose(rest);
    CkOAuth2W_Dispose(oauth2);
    CkStringBuilderW_Dispose(sbReq);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(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
  }
}