2014-11-04 97 views
6

当日历中创建新活动时,我成功地将Google日历中的推送通知导入到我的系统中。 推送通知在POST身体已经没有数据和POST头是这些:如何从Google日历中获取活动详情

[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/[email protected]/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) 

哪里是在日历中创建的新事件的详细信息? 我如何得到它们?

网上信息和谷歌文档中的任何信息(一直在寻找小时): https://developers.google.com/google-apps/calendar/v3/push

到哪里都是在事件的详细信息?

UPDATE:

我使用此代码设置我的日历的手表:

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

这是通道的细节我发送给谷歌日历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 
    (
    ) 

我仍然会在响应中获得相同的资源ID,并在日历中创建每个新事件!为什么我无法获得刚刚创建的事件的事件ID?我做错了什么?我在看事件或频道吗?

我得到的答复仍然是上面提到的答复,它始终具有相同的资源ID。

+0

我是否应该在推送通知本身中接收触发推送通知的事件详细信息?如果不是,我怎么知道哪个事件改变触发了它? – Rodniko 2014-11-04 17:49:43

+0

@rodnika不幸的没有。请参阅下面的答案。总之,你需要做一个同步来获得改变的事件。 – FullStack 2015-04-06 04:21:55

+0

http:// stackoverflow可能存在重复。com/questions/18308751/response-from-google-regard-push-notification/ – FullStack 2015-04-06 04:22:37

回答

0

要获取活动详细信息,您需要提出GET请求,该请求应该返回资源信息作为JSON响应。您可以通过传入日历ID和事件ID(在这种情况下,eventId应该是您的资源ID,假设您的通知设置为监视事件)。

+1

谢谢你的回应,Andy。我收到的资源始终具有相同的资源ID,无论我在日历中添加了哪个新事件。根据你的回复,我根本不会观看事件,因为那样我就会在新事件的每个推送通知消息中获得不同的资源ID? – Rodniko 2014-11-05 05:08:34

+0

我更新了帖子,以便您看到手表的代码。我在看频道或活动吗?如果我观察事件,为什么我不把新的事件ID作为资源ID? – Rodniko 2014-11-05 06:24:57

+1

您确定我应该在推送通知响应中的“X-Goog-Resource-ID”参数中获取我在日历中添加的新事件的事件ID吗? – Rodniko 2014-11-05 07:19:35

0

您缺少增量同步。从the creators themselves根据我的口味略微修改:

应用程序需要做的第一件事是获得新的推送功能是订阅感兴趣的日历。当日历发生变化时,Google会通知您的应用,应用会执行API调用以获取更新。

举一个例子,假设你有一个日历[email protected]。您的应用托管在带有my-host.com域名的服务器上,推送通知应发送到HTTPS Web挂钩https://my-host.com/notification

每次[email protected]发生更改时,Google Calendar服务器都会触发Web - 挂钩回调在https://my-host.com/notification。收到回调后,该应用需要执行incremental sync

相关问题