谷歌日历推送通知手表命令在php


Google Calendar Push Notification watch command in php

我正在使用php watch注释:

$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);

这个命令工作正常,我得到了响应:

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 ( ) ) 
然而

;在我的设置url,我没有得到任何消息时,我的日历发生了变化。我错过什么了吗?

我有一个类似的问题,这是由我的应用程序的身份验证引起的。

尝试向https://www.exampel.com/app/notification发送post请求,看是否收到。如果没有,请仔细检查您的路由或身份验证。

还要确保端点是有效的https URL。不允许使用自签名证书。

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

我今天遇到了这个问题,所以我想在这里补充一些细节。

Google只发送标题到你的URL。所以如果你在等待获得一些数据(就像我一样),你不会得到任何(除了某些情况)。

查看谷歌日历API文档接收通知

了解通知消息格式

所有通知消息都包含一组带有X-Goog前缀的HTTP头。某些类型的通知还可以包含消息体。

这是我在webhook回调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

我还发现了一些额外的代码示例,如果你想在没有客户端库的情况下向Google API发出请求,你可以使用它们。