0

I was creating, deleting events but the only thing was changing is the X-Goog-Message-Number

How can I differentiate watch events one from other?

So I've created watch event with PHP

$channel->setAddress('https://xxxx/handle.php');
$watchEvent = $calendar->events->watch('primary', $channel);

And when a new event comes to handle.php I've only got a header and the $_POST is empty

Here is the json

{"Content-Length":"0","Accept-Encoding":"gzip, deflate, br","User-Agent":"APIs-Google; (+https:\/\/developers.google.com\/webmasters\/APIs-Google.html)","Connection":"keep-alive","X-Goog-Resource-Uri":"https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/primary\/events?alt=json","X-Goog-Resource-Id":"xxxxxxx","X-Goog-Message-Number":"xxx646","X-Goog-Resource-State":"exists","X-Goog-Channel-Expiration":"Fri, 19 Aug 2022 14:52:46 GMT","X-Goog-Channel-Id":"xxxxx","Accept":"*\/*","Host":"xxxxxxx","Content-Type":""}
  • I'd guess Google sends you JSON. Php doesn't read that into $_POST, you have to decode it yourself. See https://stackoverflow.com/questions/18866571/receive-json-post-with-php – ADyson Aug 13 '22 at 05:06
  • @ADyson `file_get_contents('php://input')` gives me empty data when google sends it. I've done POST request to my handle.php and I see that I receive data – Taylan Karaman Aug 13 '22 at 10:24
  • Ok. What does google's documentation say that the request will contain? – ADyson Aug 13 '22 at 10:52
  • When I look at json I says: `"Accept-Encoding":"gzip, deflate, br"` – Taylan Karaman Aug 13 '22 at 11:30
  • That isn't what I asked – ADyson Aug 13 '22 at 12:10
  • "Notification messages posted by the Google Calendar API to your receiving URL do not include a message body." – Taylan Karaman Aug 13 '22 at 14:47
  • OK. Would have been good to put that in your question, then we didn't spend time trying to check the body data. – ADyson Aug 14 '22 at 04:03
  • According to https://developers.google.com/calendar/api/v3/reference/calendarList/watch, when you first created the watch it would have returned you a unique Resource ID to identify the channel you created. I can see there is a resource ID in the headers you're getting. So it looks like that's how you're supposed to identify it. You can also specify a particular token string yourself when you create the channel, which gets passed back to you in every request. – ADyson Aug 14 '22 at 04:07
  • Is that what you're asking? I'm unsure what difference you're expecting/hoping to see in each message? – ADyson Aug 14 '22 at 04:13
  • I've created appointments on my google calendar. I want to catch events happening simultaneously. Resource ID helps us to find the calendar yes, but I don't know which event the notification is bound to. That's a problem because sometimes and event notification might come with delay and maybe at that time another event is created and that second notification is sent before the first one. Or a second case where 2 events happens concurrent – Taylan Karaman Aug 14 '22 at 08:45
  • It only tells you that something happened to the calendar, you don't get specifics. You then have to query the calendar to find out exactly what has happened. More details here: https://stackoverflow.com/a/70962273/5947043 – ADyson Aug 14 '22 at 11:07
  • Great. I voted this question as a duplicate of [Is it possible to detect changes by participants to Google Calendar events?](https://stackoverflow.com/questions/70958047/is-it-possible-to-detect-changes-by-participants-to-google-calendar-events) – ADyson Aug 15 '22 at 12:05

0 Answers0