Creates a new calendar. (i.e. Adds an entry to the user's calendar list.)
#include <CkRest.h>
#include <CkOAuth2.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
void ChilkatSample(void)
{
CkRest rest;
bool success;
// Provide a previously obtained OAuth2 access token.
CkOAuth2 oauth2;
oauth2.put_AccessToken("OAUTH2_ACCESS_TOKEN");
rest.SetAuthOAuth2(oauth2);
success = rest.Connect("www.googleapis.com",443,true,true);
if (success != true) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
CkJsonObject jsonReq;
jsonReq.UpdateString("summary","test calendar abc");
CkStringBuilder sbReq;
jsonReq.EmitSb(sbReq);
rest.AddHeader("Content-Type","application/json");
CkStringBuilder sbJson;
success = rest.FullRequestSb("POST","/calendar/v3/calendars",sbReq,sbJson);
if (success != true) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
if (rest.get_ResponseStatusCode() != 200) {
std::cout << "Received error response code: " << rest.get_ResponseStatusCode() << "\r\n";
std::cout << "Response body:" << "\r\n";
std::cout << sbJson.getAsString() << "\r\n";
return;
}
CkJsonObject json;
json.LoadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
const char *kind = 0;
const char *etag = 0;
const char *id = 0;
const char *summary = 0;
kind = json.stringOf("kind");
etag = json.stringOf("etag");
id = json.stringOf("id");
summary = json.stringOf("summary");
std::cout << "Example Completed." << "\r\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"
}