What methods can be used to filter events from multiple calendars when using the Google Calendar API in PHP?

When using the Google Calendar API in PHP to retrieve events from multiple calendars, you may want to filter the events based on certain criteria, such as date range, keywords, or event type. One way to achieve this is by using query parameters in the API request to specify the filtering criteria. You can use parameters like 'timeMin', 'timeMax', 'q', or 'orderBy' to narrow down the events that are returned.

// Set the parameters for filtering events
$params = array(
    'timeMin' => '2022-01-01T00:00:00Z',
    'timeMax' => '2022-12-31T23:59:59Z',
    'q' => 'meeting',
    'orderBy' => 'startTime'
);

// Make the API request to retrieve events from multiple calendars with the specified parameters
$events = $service->events->listEvents('primary', $params);
foreach ($calendars as $calendarId) {
    $events = array_merge($events, $service->events->listEvents($calendarId, $params));
}

// Loop through the filtered events and do something with them
foreach ($events as $event) {
    // Do something with the event
}