php中的Google Calendar Push Notification监视命令

问题描述 投票:4回答:3

我正在使用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 ( ) ) 

然而;在我的设置网址中,当我的日历中的某些内容发生变化时,我不会收到任何消息。我错过了什么!?

php google-api-php-client
3个回答
1
投票

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

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


1
投票

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

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


0
投票

我今天遇到了这个问题,所以想在这里添加更多细节。

Google只会将标头发送到您的网址。因此,如果您正在等待获取某些数据(就像我一样),您将无法获得任何数据(除了某些情况)。

检查这个Google Calendar API docs for Receiving Notifications

了解通知邮件格式

所有通知消息都包含一组具有X-Goog前缀的HTTP标头。某些类型的通知还可以包括消息正文。

以下是我在webhook回调网址中收到的标题。

[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

我还发现了一些additional code sample here,如果你想在没有客户端库的情况下向Google API发出请求,你可以使用它。

希望这能有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.