Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Spatie icalendar-generator

Hello,

I read the Spatie icalendar-generator documentation and I really don't understand how it would be possible for Google Calendar to refresh the calendar each 5 seconds just with this code.

https://github.com/spatie/icalendar-generator#use-with-laravel

Calendar::create('Laracon Online')
    ->refreshInterval(5)
    ...
You can use Laravel Responses to stream to calendar applications:

$calendar = Calendar::create('Laracon Online');

return response($calendar->get())
    ->header('Content-Type', 'text/calendar; charset=utf-8');

What should I understand here ?

What I'm looking to do is : export an events list to Google Calendar and periodically refresh automatically Google Calendar to retrieve the events updates.

I think that it will be necessary to use the Google Calendar API for example ?

But then what's the utility of the refreshInterval() function from the Spatie package ?

Thanks for your help to understand this.

V

0 likes
2 replies
LaryAI's avatar
Level 58

The refreshInterval() function from the Spatie iCalendar Generator package is used to set the refresh interval for iCalendar feeds. This function is not related to Google Calendar's automatic refresh feature. If you want to periodically refresh a Google Calendar, you will need to use the Google Calendar API. You can use the Spatie iCalendar Generator package to generate the iCalendar feed and then use the Google Calendar API to import the feed into a Google Calendar. Once the feed is imported, Google Calendar will automatically refresh the feed at regular intervals. Here's an example of how you can use the Spatie iCalendar Generator package and the Google Calendar API to periodically refresh a Google Calendar:

// Generate the iCalendar feed using the Spatie iCalendar Generator package
$calendar = Calendar::create('Laracon Online')
    ->event(...)
    ->event(...)
    ->refreshInterval(5);

// Import the iCalendar feed into a Google Calendar using the Google Calendar API
$client = new Google_Client();
$client->setAuthConfig('path/to/credentials.json');
$service = new Google_Service_Calendar($client);

$calendarId = 'primary';
$event = new Google_Service_Calendar_Event();
$event->setICalUID('...');
$event->setSequence(0);
$event->setICalUID('...');
$event->setSummary('...');
$event->setStart('...');
$event->setEnd('...');
$event->setLocation('...');
$event->setDescription('...');
$event->setExtendedProperties(['private' => ['ical' => $calendar->get()]]);

$service->events->insert($calendarId, $event);

In this example, we generate the iCalendar feed using the Spatie iCalendar Generator package and set the refresh interval to 5 seconds. We then import the iCalendar feed into a Google Calendar using the Google Calendar API. We set the ical property of the extendedProperties field to the iCalendar feed generated by the Spatie package. This tells Google Calendar to use the iCalendar feed as the source for the events in the calendar. Once the feed is imported, Google Calendar will automatically refresh the feed at regular intervals.

vincent15000's avatar

@LaryAI It seems to be magic. How Google Calendar could know the server address to retrieve the last events and refresh the calendar ?

1 like

Please or to participate in this conversation.