7

i succeeded in getting a push notification from google calendar into my system, when a new event is created in the calendar. the push notification has no data in the POST body and the POST headers are these:

[Host] => xxxxxx.xxxx.com
[Content-Type] => application/json; charset=UTF-8
[Accept] => */*
[X-Goog-Channel-ID] => xxxxxxx-xxxxxxxx-8824-f0c2166878be
[X-Goog-Channel-Expiration] => Thu, 04 Dec 2014 04:27:13 GMT
[X-Goog-Resource-State] => exists
[X-Goog-Message-Number] => 11897215
[X-Goog-Resource-ID] => xxxxxxxxxx-xxxx-pSbC27qOUfg
[X-Goog-Resource-URI] => https://www.googleapis.com/calendar/v3/calendars/xxxxxxx@gmail.com/events?key=AIzaSyC_0nytiZWHfabrpWiExxxxxxxxxxx&alt=json
[Content-Length] => 0
[Connection] => Keep-alive
[Accept-Encoding] => gzip,deflate
[User-Agent] => APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)

where are the new event details that was created in the calendar? how do i get them?

no information online and no information in google documentation (been searching for hours): https://developers.google.com/google-apps/calendar/v3/push

where are the event details??

UPDATE:

i set a watch on my calendar using this code:

service = new Google_Service_Calendar($client);         
$channel =  new Google_Service_Calendar_Channel($client);
$uuid = gen_uuid();
$channel->setId($uuid);
$channel->setType('web_hook');
$channel->setExpiration('1919995862000');

global $sugar_config;
$address = $sugar_config['site_url'] . "/index.php?entryPoint=updateFromCal";
$channel->setAddress($address);
$watchEvent = $service->events->watch($bean->google_cal_id_c, $channel);

This is the channel details i send to google calendar api:

[address] => https://mydomainXXXX/index.php?entryPoint=updateFromCal
[expiration] => 1919995862000
[id] => xxxxxxxxxxxxxxx--4558-ac19-b82e0ca32206
[kind] => 
[params] => 
[payload] => 
[resourceId] => 
[resourceUri] => 
[token] => 
[type] => web_hook
[modelData:protected] => Array
    (
    )

[processed:protected] => Array
    (
    )

i still get the same resource ID in the response, with every new event i create in the calendar! why can't i get the event ID of the event i just created? what did i do wrong? am i watching events or channels?

the reply i get is still the one mentioned above, its with the same resource id all the time.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
Rodniko
  • 4,926
  • 20
  • 69
  • 93
  • am i supposed to receive the event details, that triggered the push notification, in the push notification itself? if not, how can i know which event change triggered it? – Rodniko Nov 04 '14 at 17:49
  • @rodnika unfortunately no. See my answer below. In short you need to do a sync to get the event that changed. – FullStack Apr 06 '15 at 04:21
  • Possible duplicate of http://stackoverflow.com/questions/18308751/response-from-google-regarding-push-notification/ – FullStack Apr 06 '15 at 04:22
  • I think you might save the UUID you generated so later you can fetch the event using that value – Joaquín L. Robles Nov 19 '21 at 15:40

3 Answers3

10

The push does not contain any data. It only tells you that something changed in that resource. You will need to do a list request to find out what it was. Preferably this list request will be an incremental sync. Take a look into how to do synchronization here: https://developers.google.com/google-apps/calendar/v3/sync

luc
  • 3,642
  • 1
  • 18
  • 21
  • You're right. First you set a "watch" so that Google knows when to send you a push notification when your watched resource has changed (https://developers.google.com/calendar/v3/push). Then you do an incremental sync to check WHICH resources were changed specifically. – Edward Oct 05 '18 at 17:24
0

You are missing the incremental sync. From the creators themselves slightly revised according to my tastes:

The first thing the app needs to do is get the new push functionality is to subscribe to a calendar of interest. When a calendar changes, Google will notify your app and the app does an API call to get the update.

As an example, let’s assume you have a calendar my_calendar@my-host.com. Your app is hosted on a server with my-host.com domain and push notifications should be delivered to an HTTPS web-hook https://my-host.com/notification

Every time my_calendar@my-host.com changes, the Google Calendar server will trigger a web-hook callback at https://my-host.com/notification. After receiving the callback the app needs to do an incremental sync.

FullStack
  • 5,902
  • 4
  • 43
  • 77
-1

To get the event details, you need to make a GET request, which should return the resource information as a JSON response. You can do so by passing in the Calendar ID and the Event ID (the eventId in this case should be your resource-ID, assuming that your notification was set to watch events).

Andy
  • 2,374
  • 3
  • 17
  • 20
  • 1
    Thank you for your response, Andy. the resource i receive has always the same resource ID, no matter which new event i add in the calendar. according to your reply, i don't watch events at all, because then i would have got a different resource ID with every push notification message on a new event right? – Rodniko Nov 05 '14 at 05:08
  • i updated the post so you can see the code of the watch. am i watching channels or events? if i watch events, why don't i egt the new event id as the resource ID? – Rodniko Nov 05 '14 at 06:24
  • 1
    Are you sure i'm supposed to get the event ID of the new event i added in the calendar, in the "X-Goog-Resource-ID" parameter in the push notification response? – Rodniko Nov 05 '14 at 07:19
  • 1
    I agree the documentation could be more clear, but I believe that the resourceId is not the eventId. You need to try @luc's or my answer. – FullStack Apr 06 '15 at 03:25