Ideal Bakija
Ideal Bakija

Reputation: 639

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!?

Upvotes: 9

Views: 4090

Answers (3)

hriziya
hriziya

Reputation: 1172

I have faced this issue today, so want to add some more details here.

Google only send the headers to your URL. so if you are waiting for getting some data (just like me) you won't get any (except some cases).

Check this Google Calendar API docs for Receiving Notifications

Understanding the notification message format

All notification messages include a set of HTTP headers that have X-Goog- prefixes. Some types of notifications can also include a message body.

Here are the headers I received in my webhook callback URL.

[Host] => mydomain.com
[X-Goog-Channel-ID] => 10ddfddt0-a995-10f4-1254e2-0000000a0a0609001
[X-Goog-Channel-Expiration] => Thu, 11 Jan 2018 10:04:04 GMT
[X-Goog-Resource-State] => exists
[X-Goog-Message-Number] => 2526579
[X-Goog-Resource-ID] => 9OG_a-ECJycPkpNR1ZrWSon5_i1
[X-Goog-Resource-URI] => https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=250&alt=json
[Content-Length] => 0
[Connection] => keep-alive
[User-Agent] => APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
[Accept-Encoding] => gzip,deflate,br

I also found some additional code sample here which you can use if you want to make the request to Google API without client library.

Hope this help someone.

Upvotes: 0

Gaurav Gupta
Gaurav Gupta

Reputation: 5416

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

Upvotes: 0

Tom Wright
Tom Wright

Reputation: 2861

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.

Upvotes: 1

Related Questions