PHP ActiveX Google Calendar: List Events on a Calendar

Back to Index

Returns events on the specified calendar.
This example returns the events for the calendar having the ID = "support@chilkatcloud.com"

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/list


<?php

$rest = new COM("Chilkat_9_5_0.Rest");

//   Provide a previously obtained OAuth2 access token.
$oauth2 = new COM("Chilkat_9_5_0.OAuth2");
$oauth2->AccessToken = 'OAUTH2_ACCESS_TOKEN';
$rest->SetAuthOAuth2($oauth2);

$success = $rest->Connect('www.googleapis.com',443,1,1);
if ($success != 1) {
    print $rest->LastErrorText . "\n";
    exit;
}

$sbJson = new COM("Chilkat_9_5_0.StringBuilder");
$success = $rest->FullRequestNoBodySb('GET','/calendar/v3/calendars/support@chilkatcloud.com/events',$sbJson);
if ($success != 1) {
    print $rest->LastErrorText . "\n";
    exit;
}

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

$json = new COM("Chilkat_9_5_0.JsonObject");
$json->LoadSb($sbJson);

//  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');
$summary = $json->stringOf('summary');
$updated = $json->stringOf('updated');
$timeZone = $json->stringOf('timeZone');
$accessRole = $json->stringOf('accessRole');
$nextSyncToken = $json->stringOf('nextSyncToken');
$i = 0;
$count_i = $json->SizeOfArray('defaultReminders');
while ($i < $count_i) {
    $json->I = $i;
    $method = $json->stringOf('defaultReminders[i].method');
    $minutes = $json->IntOf('defaultReminders[i].minutes');
    $i = $i + 1;
}

$i = 0;
$count_i = $json->SizeOfArray('items');
while ($i < $count_i) {
    $json->I = $i;
    $kind = $json->stringOf('items[i].kind');
    $etag = $json->stringOf('items[i].etag');
    $id = $json->stringOf('items[i].id');
    $status = $json->stringOf('items[i].status');
    $htmlLink = $json->stringOf('items[i].htmlLink');
    $created = $json->stringOf('items[i].created');
    $updated = $json->stringOf('items[i].updated');
    $summary = $json->stringOf('items[i].summary');
    $creatorEmail = $json->stringOf('items[i].creator.email');
    $creatorSelf = $json->BoolOf('items[i].creator.self');
    $organizerEmail = $json->stringOf('items[i].organizer.email');
    $organizerSelf = $json->BoolOf('items[i].organizer.self');
    $startDateTime = $json->stringOf('items[i].start.dateTime');
    $endDateTime = $json->stringOf('items[i].end.dateTime');
    $iCalUID = $json->stringOf('items[i].iCalUID');
    $sequence = $json->IntOf('items[i].sequence');
    $hangoutLink = $json->stringOf('items[i].hangoutLink');
    $remindersUseDefault = $json->BoolOf('items[i].reminders.useDefault');
    $location = $json->stringOf('items[i].location');
    $i = $i + 1;
}

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

?>

Sample JSON Response Body

{
  "kind": "calendar#events",
  "etag": "\"p32gd13choqmte0g\"",
  "summary": "support@chilkatcloud.com",
  "updated": "2017-11-07T22:49:27.892Z",
  "timeZone": "America/Chicago",
  "accessRole": "owner",
  "defaultReminders": [
    {
      "method": "popup",
      "minutes": 10
    }
  ],
  "nextSyncToken": "CKDQjZHGrdcCEKDQjZHGrdcCGAU=",
  "items": [
    {
      "kind": "calendar#event",
      "etag": "\"3004746854620000\"",
      "id": "5jt9fopfg3rr9eftegiuq7gc5k",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NWp0OWZvcGZnM3JyOWVmdGVnaXVxN2djNWsgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:07.000Z",
      "updated": "2017-08-10T13:57:07.310Z",
      "summary": "Run 10 miles",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T13:00:00-05:00"
      },
      "iCalUID": "5jt9fopfg3rr9eftegiuq7gc5k@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.5jt9fopfg3rr9eftegiuq7gc5k",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004746898118000\"",
      "id": "7dvh49vd219r3sq7jdueieu8rc",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=N2R2aDQ5dmQyMTlyM3NxN2pkdWVpZXU4cmMgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:29.000Z",
      "updated": "2017-08-10T13:57:29.059Z",
      "summary": "Eat Giordano's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T15:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T16:00:00-05:00"
      },
      "iCalUID": "7dvh49vd219r3sq7jdueieu8rc@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.7dvh49vd219r3sq7jdueieu8rc",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004746915224000\"",
      "id": "5btd89ljn07bg3tlgpimcaqrro",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NWJ0ZDg5bGpuMDdiZzN0bGdwaW1jYXFycm8gc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:37.000Z",
      "updated": "2017-08-10T13:57:37.612Z",
      "summary": "Nap",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T16:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T17:30:00-05:00"
      },
      "iCalUID": "5btd89ljn07bg3tlgpimcaqrro@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.5btd89ljn07bg3tlgpimcaqrro",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915127736000\"",
      "id": "703fss5qdedn1egq80ildhslba",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NzAzZnNzNXFkZWRuMWVncTgwaWxkaHNsYmEgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:23.000Z",
      "updated": "2017-08-11T13:19:23.868Z",
      "summary": "Run 12 miles",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T09:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T10:30:00-05:00"
      },
      "iCalUID": "703fss5qdedn1egq80ildhslba@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.703fss5qdedn1egq80ildhslba",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915160212000\"",
      "id": "02pv1cpdp7vm11htnfi3ii7iie",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MDJwdjFjcGRwN3ZtMTFodG5maTNpaTdpaWUgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:40.000Z",
      "updated": "2017-08-11T13:19:40.106Z",
      "summary": "Eat Lou Malnati's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T13:00:00-05:00"
      },
      "iCalUID": "02pv1cpdp7vm11htnfi3ii7iie@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.02pv1cpdp7vm11htnfi3ii7iie",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915175982000\"",
      "id": "20l29s2idr5ggorncd3teahm0e",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MjBsMjlzMmlkcjVnZ29ybmNkM3RlYWhtMGUgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:47.000Z",
      "updated": "2017-08-11T13:19:47.991Z",
      "summary": "Nap",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T16:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T17:30:00-05:00"
      },
      "iCalUID": "20l29s2idr5ggorncd3teahm0e@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.20l29s2idr5ggorncd3teahm0e",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004969011208000\"",
      "id": "v7kvmsvsoms3hjl5uq423jqhb0",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=djdrdm1zdnNvbXMzaGpsNXVxNDIzanFoYjAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T20:48:25.000Z",
      "updated": "2017-08-11T20:48:25.604Z",
      "summary": "Eat Lou Malnati's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T13:00:00-05:00"
      },
      "iCalUID": "v7kvmsvsoms3hjl5uq423jqhb0@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.v7kvmsvsoms3hjl5uq423jqhb0",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007268672000\"",
      "id": "1p7fb5vob7vm57fepk4p1teft9",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MXA3ZmI1dm9iN3ZtNTdmZXBrNHAxdGVmdDkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:27:14.000Z",
      "updated": "2017-11-06T21:27:14.336Z",
      "summary": "Breakfast at Tiffany's",
      "location": "Tiffany's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T07:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T08:00:00-06:00"
      },
      "iCalUID": "1p7fb5vob7vm57fepk4p1teft9@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.1p7fb5vob7vm57fepk4p1teft9",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007309018000\"",
      "id": "05f5eieun35hoofbiab00ru03o",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MDVmNWVpZXVuMzVob29mYmlhYjAwcnUwM28gc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:27:34.000Z",
      "updated": "2017-11-06T21:27:34.509Z",
      "summary": "Lunch at Sushi House",
      "location": "Sushi House",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T12:30:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T13:30:00-06:00"
      },
      "iCalUID": "05f5eieun35hoofbiab00ru03o@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.05f5eieun35hoofbiab00ru03o",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007516220000\"",
      "id": "4hrv7chnc3jspepqr4ntrsq6k9",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NGhydjdjaG5jM2pzcGVwcXI0bnRyc3E2azkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:29:17.000Z",
      "updated": "2017-11-06T21:29:18.110Z",
      "summary": "Dinner at Gia Mia",
      "location": "Gia Mia",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T19:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T20:00:00-06:00"
      },
      "iCalUID": "4hrv7chnc3jspepqr4ntrsq6k9@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.4hrv7chnc3jspepqr4ntrsq6k9",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007580384000\"",
      "id": "53k665tdurv5geejkl8d9eljmp",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NTNrNjY1dGR1cnY1Z2VlamtsOGQ5ZWxqbXAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:29:50.000Z",
      "updated": "2017-11-06T21:29:50.192Z",
      "summary": "Breakfast at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T07:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T08:00:00-06:00"
      },
      "iCalUID": "53k665tdurv5geejkl8d9eljmp@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.53k665tdurv5geejkl8d9eljmp",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007628078000\"",
      "id": "27n9mbbabkur965n87ddir6m1i",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MjduOW1iYmFia3VyOTY1bjg3ZGRpcjZtMWkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:30:14.000Z",
      "updated": "2017-11-06T21:30:14.039Z",
      "summary": "Lunch at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T13:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T14:00:00-06:00"
      },
      "iCalUID": "27n9mbbabkur965n87ddir6m1i@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.27n9mbbabkur965n87ddir6m1i",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007645098000\"",
      "id": "3jmu86tk17hc21gam5l073pu1k",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=M2ptdTg2dGsxN2hjMjFnYW01bDA3M3B1MWsgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:30:22.000Z",
      "updated": "2017-11-06T21:30:22.549Z",
      "summary": "Dinner at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T19:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T20:00:00-06:00"
      },
      "iCalUID": "3jmu86tk17hc21gam5l073pu1k@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.3jmu86tk17hc21gam5l073pu1k",
      "reminders": {
        "useDefault": true
      }
    }
  ]
}