Google Calendar Push Notification watch command in php

倖福魔咒の 提交于 2019-12-22 05:31:56

问题


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


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/23930262/google-calendar-push-notification-watch-command-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!