Creates a new calendar. (i.e. Adds an entry to the user's calendar list.)
#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// Provide a previously obtained OAuth2 access token.
CkOAuth2W oauth2;
oauth2.put_AccessToken(L"OAUTH2_ACCESS_TOKEN");
rest.SetAuthOAuth2(oauth2);
success = rest.Connect(L"www.googleapis.com",443,true,true);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
CkJsonObjectW jsonReq;
jsonReq.UpdateString(L"summary",L"test calendar abc");
CkStringBuilderW sbReq;
jsonReq.EmitSb(sbReq);
rest.AddHeader(L"Content-Type",L"application/json");
CkStringBuilderW sbJson;
success = rest.FullRequestSb(L"POST",L"/calendar/v3/calendars",sbReq,sbJson);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
if (rest.get_ResponseStatusCode() != 200) {
wprintf(L"Received error response code: %d\n",rest.get_ResponseStatusCode());
wprintf(L"Response body:\n");
wprintf(L"%s\n",sbJson.getAsString());
return;
}
CkJsonObjectW json;
json.LoadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
const wchar_t *kind = 0;
const wchar_t *etag = 0;
const wchar_t *id = 0;
const wchar_t *summary = 0;
kind = json.stringOf(L"kind");
etag = json.stringOf(L"etag");
id = json.stringOf(L"id");
summary = json.stringOf(L"summary");
wprintf(L"Example Completed.\n");
}
{
"summary": "test calendar abc"
}
{
"kind": "calendar#calendar",
"etag": "\"BKjXnZpXR6E5ueFWG3UJk-2POYg/jb82ZwCZzTu1P_p3WnVVxDoJTeI\"",
"id": "chilkatcloud.com_he3bfm0ljrl7p427u8vjmg9afo@group.calendar.google.com",
"summary": "test calendar abc"
}