Search code examples
phpgoogle-apigoogle-calendar-api

google calendar watch expiration time for more than one month?


I synchronize my CRM system with Google Calendar. To do that I ask for push notifications from my users Google Calendars into my system. I have created a watch successfully and set the expiration time to year 2030, but when I receive a response from the watch event, it shows the expiration time of the watch is set to one month.

Questions:

  1. Does this mean I need to refresh the watch of each user's calendar in my system every month?
  2. Is there a way to make the watch unlimited?

My Code:

$channel =  new Google_Service_Calendar_Channel($client);
$uuid = gen_uuid(); 
$channel->setId($uuid); 
$channel->setType('web_hook'); 
$channel->setExpiration('1919995862000');
$address = $sugar_config['site_url'] . "/index.php?entryPoint=updateFromCal";   
$channel->setAddress($address); 
$watchEvent = $service->events->watch($bean->google_cal_id_c, $channel);

The response:

    [address] => 
    [expiration] => 1417667348000
    [id] => 87453668-b1fd-4468-beca-xxxxxxxxxxxx
    [kind] => api#channel
    [params] => 
    [payload] => 
    [resourceId] => xxxxxxxxx-xxxxxxxxxxx
    [resourceUri] => https://www.googleapis.com/calendar/v3/calendars/xxxxxx@gmail.com/events?key=xxxxxxxxxxxxxxxxxxxxWHxxxxxxalt=json
    [token] => 
    [type] => 
    [modelData:protected] => Array

Solution

  • A notification channel can have an expiration time, with a value determined either by your request or by any Google Calendar API internal limits or defaults (the more restrictive value is used). Currently there is no automatic way to renew a notification channel. When a channel is close to its expiration, you must create a new one by calling the watch method. Here is the link for more documentation about the notification channels.