Google Calendar API Value Notification Identification

I am successfully registering for the Google Calendar API with changes using PHP:

$service = new Google_Service_Calendar($client);
$channel =  new Google_Service_Calendar_Channel($service);
$channel->setId(<some random ID>);
$channel->setType('web_hook');
$channel->setAddress('https://www.myserver.net/triggerCode.php');
$timetoExpire = time()+3600000;
$channel->setExpiration($timetoExpire);
$watchEvent = $service->events->watch('<some_calendar_name>', $channel);

EXCEPT this only works if the line $ channel-> setExpiration is commented out.

I get an error when ttl is invalid. I tried to set the expiration time to a few seconds (e.g. 6000), the number of milliseconds (e.g. 600000) and time () plus a few milliseconds, and I always get the same error:

Invalid ttl value for channel -1402834554'

How should I fix this?

+4
source share
2 answers

Finally, he worked. This php code works:

 $service = new Google_Service_Calendar($client);
 $channel =  new Google_Service_Calendar_Channel($service);
 $channel->setId($uniqueID);
 $channel->setType('web_hook');
 $channel->setAddress('https://mydomain.net/notificationCallBack.php');

 $timetoExpire = time()+3600000;
 $optParams = array('ttl' => $timetoExpire);
 $channel->setParams($optParams);

 $watchEvent = $service->events->watch($calendarID, $channel);

42 , , 30 . , .

+3

API documentatio n , watch expiration.

:

{
  "id": string,
  "token": string,
  "type": string,
  "address": string,
  "params": {
    "ttl": string
  }
}

expiration, :

{
  "kind": "api#channel",
  "id": string,
  "resourceId": string,
  "resourceUri": string,
  "token": string,
  "expiration": long
}

, ttl, params?


FYI: expiration Date and time of notification channel expiration, expressed as a Unix timestamp, in milliseconds.

+2

Source: https://habr.com/ru/post/1546753/


All Articles