How do I get event ID from Google Calendar API?

740 Views Asked by At

Hey I'm using an API for first time, and I am confused about how to get event ID from Calendar API. Currently I'm using the sample quickstart.php file, and getting summary from this:

$results = $service->events->listEvents($calendarId, $optParams);
$events = $results->getItems();

if (empty($events)) {
    print "No upcoming events found.\n";
} else {
    print "Upcoming events:\n";
    foreach ($events as $event) {
        $start = $event->start->dateTime;
        if (empty($start)) {
            $start = $event->start->date;
        }
        printf("%s (%s)\n", $event->getSummary(), $start);
    }
}

Thanks in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

This is so simple as mention above you can fetch id by $event->ID or you can use

print_r($events) to see the data.

1
On

It's written in the CalendarList Resource representation of the documentation. id is part of the calendarList Resource object within the array of items. Within the foreach of $events

$event->id;