Creates an event based on a simple text string. (This example adds an event to the calendar with id = "support@chilkatcloud.com".)
#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 *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;
}
CkRestW_AddQueryParam(rest,L"text",L"Dentist Appointment");
CkRestW_AddQueryParam(rest,L"sendNotifications",L"true");
sbReq = CkStringBuilderW_Create();
sbJson = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/calendar/v3/calendars/support@chilkatcloud.com/events/quickAdd",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");
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);
CkStringBuilderW_Dispose(sbReq);
CkStringBuilderW_Dispose(sbJson);
CkJsonObjectW_Dispose(json);
}
{
"kind": "calendar#event",
"etag": "\"3020352941868000\"",
"id": "52e7uk7j7vl5dosj7b25memov0",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=NTJlN3VrN2o3dmw1ZG9zajdiMjVtZW1vdjAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
"created": "2017-11-08T21:27:50.000Z",
"updated": "2017-11-08T21:27:50.934Z",
"summary": "Dentist Appointment",
"creator": {
"email": "support@chilkatcloud.com",
"self": true
},
"organizer": {
"email": "support@chilkatcloud.com",
"self": true
},
"start": {
"dateTime": "2017-11-08T15:27:50-06:00"
},
"end": {
"dateTime": "2017-11-08T16:27:50-06:00"
},
"iCalUID": "52e7uk7j7vl5dosj7b25memov0@google.com",
"sequence": 0,
"hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.52e7uk7j7vl5dosj7b25memov0",
"reminders": {
"useDefault": true
}
}