PHP Extension Google Calendar: Create (Insert) a Calendar

Back to Index

Creates a new calendar. (i.e. Adds an entry to the user's calendar list.)



// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:

$rest = new CkRest();

//   Provide a previously obtained OAuth2 access token.
$oauth2 = new CkOAuth2();

$success = $rest->Connect('',443,true,true);
if ($success != true) {
    print $rest->lastErrorText() . "\n";

//  The following code creates the JSON request body.
//  The JSON created by this code is shown below.
$jsonReq = new CkJsonObject();
$jsonReq->UpdateString('summary','test calendar abc');

$sbReq = new CkStringBuilder();


$sbJson = new CkStringBuilder();
$success = $rest->FullRequestSb('POST','/calendar/v3/calendars',$sbReq,$sbJson);
if ($success != true) {
    print $rest->lastErrorText() . "\n";

if ($rest->get_ResponseStatusCode() != 200) {
    print 'Received error response code: ' . $rest->get_ResponseStatusCode() . "\n";
    print 'Response body:' . "\n";
    print $sbJson->getAsString() . "\n";

$json = new CkJsonObject();

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

$kind = $json->stringOf('kind');
$etag = $json->stringOf('etag');
$id = $json->stringOf('id');
$summary = $json->stringOf('summary');

print 'Example Completed.' . "\n";


Sample JSON Request Body

   "summary": "test calendar abc"

Sample JSON Response Body

  "kind": "calendar#calendar",
  "etag": "\"BKjXnZpXR6E5ueFWG3UJk-2POYg/jb82ZwCZzTu1P_p3WnVVxDoJTeI\"",
  "id": "",
  "summary": "test calendar abc"