Changes the color of a particular event. The calendar and event are specified by ID. This example changes the color for an event (id = 52e7uk7j7vl5dosj7b25memov0) on the calendar (id = support@chilkatcloud.com).
This changes the event to colorId = "6" which seems to be an orange-ish color..
#include <C_CkRestW.h>
#include <C_CkOAuth2W.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
HCkOAuth2W oauth2;
HCkJsonObjectW jsonReq;
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 *colorId;
const wchar_t *creatorEmail;
BOOL creatorSelf;
const wchar_t *organizerEmail;
BOOL organizerSelf;
const wchar_t *startDateTime;
const wchar_t *endDateTime;
const wchar_t *iCalUID;
int sequence;
const wchar_t *hangoutLink;
BOOL remindersUseDefault;
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;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
jsonReq = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(jsonReq,L"colorId",L"6");
sbReq = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(jsonReq,sbReq);
CkRestW_AddHeader(rest,L"Content-Type",L"application/json");
sbJson = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"PATCH",L"/calendar/v3/calendars/support@chilkatcloud.com/events/52e7uk7j7vl5dosj7b25memov0",sbReq,sbJson);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
CkJsonObjectW_Dispose(jsonReq);
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);
CkJsonObjectW_Dispose(jsonReq);
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");
colorId = CkJsonObjectW_stringOf(json,L"colorId");
creatorEmail = CkJsonObjectW_stringOf(json,L"creator.email");
creatorSelf = CkJsonObjectW_BoolOf(json,L"creator.self");
organizerEmail = CkJsonObjectW_stringOf(json,L"organizer.email");
organizerSelf = CkJsonObjectW_BoolOf(json,L"organizer.self");
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");
wprintf(L"Example Completed.\n");
CkRestW_Dispose(rest);
CkOAuth2W_Dispose(oauth2);
CkJsonObjectW_Dispose(jsonReq);
CkStringBuilderW_Dispose(sbReq);
CkStringBuilderW_Dispose(sbJson);
CkJsonObjectW_Dispose(json);
}
{
"colorId": "6"
}
{
"kind": "calendar#event",
"etag": "\"3021538600038000\"",
"id": "52e7uk7j7vl5dosj7b25memov0",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=NTJlN3VrN2o3dmw1ZG9zajdiMjVtZW1vdjAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
"created": "2017-11-08T21:27:50.000Z",
"updated": "2017-11-15T18:08:20.019Z",
"summary": "Dentist Appointment",
"colorId": "6",
"creator": {
"email": "support@chilkatcloud.com",
"self": true
},
"organizer": {
"email": "support@chilkatcloud.com",
"self": true
},
"start": {
"dateTime": "2017-11-27T10:30:00-06:00"
},
"end": {
"dateTime": "2017-11-27T11:30:00-06:00"
},
"iCalUID": "52e7uk7j7vl5dosj7b25memov0@google.com",
"sequence": 1,
"hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.52e7uk7j7vl5dosj7b25memov0",
"reminders": {
"useDefault": true
}
}