【发布时间】:2015-08-11 02:28:04
【问题描述】:
我似乎无法理解this article。
我正在尝试在我的网络应用程序和 Google 日历之间创建 2 向事件同步。我的活动已成功同步到 Google 日历,但 Google 发送给我的推送通知没有任何用处。
当我创建一个新事件,然后创建一个手表时:
$channel = new Google_Service_Calendar_Channel();
$channel->setId($watchId);
$channel->setType('web_hook');
$channel->setAddress(URL::route('gapi.watchEvent'));
$channel->setResourceId($seg->gapi_event_id); // does this do anything??
$channel->setToken(json_encode(['segment_id'=>$seg->id]));
$channel->setParams([
'ttl' => 2628000, // is this respected??
]);
$watchResp = $calendarService->events->watch($googleCalendarId, $channel);
首先,$channel->setResourceId 有什么作用吗?我想收听特定事件的更改,但似乎总是给我整个日历的通知。
Google 发送给我的标头如下所示:
"X-Goog-Channel-Id": "qJSdaxkKKkXXXXXXXXXX",
"X-Goog-Channel-Expiration": "Thu, 10 Sep 2015 01:45:57 GMT",
"X-Goog-Resource-State": "exists",
"X-Goog-Message-Number": "1811101",
"X-Goog-Resource-Id": "wBkuOkYwEhDiXXXXXXXXX",
"X-Goog-Resource-Uri": "https://www.googleapis.com/calendar/v3/calendars/9t4rmmb2rfdvcXXXXXXX@group.calendar.google.com/events?alt=json",
X-Goog-Channel-Id 是我选择的手表 ID。 X-Goog-Resource-Uri 似乎只是日历的链接。我不知道X-Goog-Resource-Id 是什么。它似乎既不是我的日历 ID,也不是我的活动 ID。
我只想知道哪些数据发生了变化?如何从推送通知中提取该信息?
我不在乎是否必须订阅我的应用创建的每个事件,或者每个日历只订阅一次。
【问题讨论】:
-
创建watch请求时,id":string,应该是channelId,一旦请求成功,response就会包含资源的resource id,比如想要事件,您应该将观看请求发送到 events.watchhttps://developers.google.com/google-apps/calendar/v3/reference/events/watch
-
X-Goog-Resource-Id 是您的资源的资源 ID,并且是唯一的。它是给您的资源的编号。如果您正在观看活动,那么对日历上的活动进行任何更改,您都会收到通知。检查链接developers.google.com/google-apps/calendar/v3/push 中的接收通知部分。然后你可以做 events.list 来检查变化。
-
这很模糊。事实证明,“资源 ID”是“手表”的。这不是我生成的手表 ID(又名频道 ID),也不是日历 ID,也不是事件 ID——它是 Google 的内部手表标识符。