如何从谷歌日历中获取活动详情

时间:2014-11-04 08:03:47

标签: php calendar google-api google-calendar-api

当我在日历中创建新事件时,我成功地从谷歌日历中获取推送通知到我的系统中。 推送通知在POST正文中没有数据,POST标题是:

[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/xxxxxxx@gmail.com/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

事件详情在哪里?

更新

我使用以下代码在我的日历上设置了一个手表:

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。

3 个答案:

答案 0 :(得分:8)

推送不包含任何数据。它只告诉你该资源发生了变化。您需要执行列表请求以查明它是什么。优选地,该列表请求将是增量同步。请在此处查看如何进行同步:https://developers.google.com/google-apps/calendar/v3/sync

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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

举个例子,我们假设您有一个日历my_calendar@my-host.com。您的应用程序托管在具有my-host.com域的服务器上,推送通知应该发送到HTTPS网络挂钩https://my-host.com/notification

每次my_calendar@my-host.com更改时,Google日历服务器都会在https://my-host.com/notification触发网络勾回调。收到回调后,应用需要执行incremental sync

相关问题