Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar Push Notification watch command in php

I am using the php watch commant:

$service = new Google_Service_Calendar($client);


$channel =  new Google_Service_Calendar_Channel($client);
$channel->setId('20fdedbf0-a845-11e3-1515e2-0800200c9a6689111');
$channel->setType('web_hook');
$channel->setAddress('https://www.exampel.com/app/notification');

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

This command works fine and I get the response:

Google_Service_Calendar_Channel Object ( [address] => [expiration] => 1401960485000 [id] => 20fdedbf0-a845-11e3-1515e2-0800200c9a6689111 [kind] => api#channel [params] => [payload] => [resourceId] => HZjSdbhwcd5KMKEA3ATA31LoR-w [resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?key=AIzaSyBl_Y7Y4eQDve-0DjwzBEP7_qOLo-67ouY&alt=json [token] => [type] => [modelData:protected] => Array ( ) [processed:protected] => Array ( ) ) 

However; In my set up url I don't get any message when something changes in my calendar. Am I missing something!?

like image 896
Ideal Bakija Avatar asked May 29 '14 09:05

Ideal Bakija


People also ask

How do I request push notifications from Google Calendar?

To request push notifications, you need to set up a notification channel for each resource you want to watch. After your notification channels are set up, the Google Calendar API will inform your application when any watched resource changes.

How do I watch for changes to a Google Calendar resource?

Each watchable Google Calendar API resource has an associated watch method at a URI of the following form: To set up a notification channel for messages about changes to a particular resource, send a POST request to the watch method for the resource.

How do I use push notifications?

This document describes how to use push notifications that inform your application when a resource changes. The Google Calendar API provides push notifications that let you watch for changes to resources. You can use this feature to improve the performance of your application.

Can the Google Calendar API send notifications to an HTTPS address?

Note that the Google Calendar API will be able to send notifications to this HTTPS address only if there is a valid SSL certificate installed on your web server. Invalid certificates include: Self-signed certificates. Certificates signed by an untrusted source. Certificates that have been revoked.


2 Answers

I had a similar issue which was caused by authentication on my application.

Try sending a post request to https://www.exampel.com/app/notification and see if it is received. If not, double check your routing or authentication.

like image 122
Tom Wright Avatar answered Nov 17 '22 19:11

Tom Wright


Also ensure that the endpoint is a valid https URL. Self-signed certificates are not allowed.

Source: https://developers.google.com/google-apps/calendar/v3/push

like image 23
Gaurav Gupta Avatar answered Nov 17 '22 18:11

Gaurav Gupta