如何从谷歌日历获取活动详细信息

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

当日历中创建新事件时,我成功地将谷歌日历的推送通知发送到我的系统中。 推送通知的 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/[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

活动详情在哪里??

更新:

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

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。

php calendar google-api google-calendar-api
4个回答
10
投票

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


0
投票

您缺少增量同步。来自创作者自己根据我的口味稍作修改:

应用程序需要做的第一件事是获得新的推送功能,即订阅感兴趣的日历。当日历更改时,Google 将通知您的应用程序,并且该应用程序会调用 API 来获取更新。

举个例子,假设您有一个日历 [电子邮件受保护]。您的应用程序托管在具有 my-host.com 域的服务器上,并且推送通知应传递到 HTTPS web-hook https://my-host.com/notification

每次 [受保护的电子邮件] 发生变化时,Google 日历服务器都会在 https://my-host.com/notification 触发网络挂钩回调。收到回调后,应用程序需要执行增量同步


0
投票

在通知回调中,您将在标题中获得一些信息,这些信息在Google文档中描述https://developers.google.com/calendar/api/guides/push

查看所有按键

request.headers.to_h.keys

要从标题中查找任何重要值,可以是

Resource-ID

request.headers['X-Goog-Resource-ID']

-1
投票

要获取事件详细信息,您需要发出 GET 请求,该请求应以 JSON 响应形式返回资源信息。您可以通过传入日历 ID 和事件 ID 来完成此操作(本例中的 eventId 应是您的资源 ID,假设您的通知已设置为监视事件)。

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