Reputation: 5124
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:
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/[email protected]/events?key=xxxxxxxxxxxxxxxxxxxxWHxxxxxxalt=json
[token] =>
[type] =>
[modelData:protected] => Array
Upvotes: 5
Views: 2661
Reputation: 720
You can create an Oauth and Service Account and use that instead to authenticate your Google Calendar Request:
1- Go to gcp, create a project, enable calendar api, create oAuth Account and create Service Account.
2- After creating oAuth, download the oAuth json file.
3- After creating the service account go to keys
and create a new json key and also download. (You are going to use this one for authentication)
4- Go to the calendar you want to access with your api and add share the calendar with your previously created Google Service Account, set the permissions according to your needs
Done, now you can access the api without the need to refresh the token, nor create one. You just need to add the oauth json and the service account json in your files and call them when required. You should use the jwtClient
to create your auth. All the rest should be the same.
Upvotes: 0
Reputation: 1035
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.
Upvotes: 4