google 日历的推送通知不起作用
Push notification for google calendar not working
我正在使用 php 监视命令:
try {
$service = new Google_Service_Calendar($this->gapi->client);
$channel = new Google_Service_Calendar_Channel($this->gapi->client);
$uuid = '27baf74c-59****************';
$channel->setId($uuid);
$channel->setType('web_hook');
$channel->setToken($uuid);
$channel->setAddress('https://*********.com/calendar_webhook');
$watchEvent = $service->events->watch('primary',$channel);
print_r($watchEvent);
} catch (Exception $e) {
print_r($e->getMessage());
}
之后我收到了 $watchEvent
这样的回复
Google_Service_Calendar_Channel Object
(
[internal_gapi_mappings:protected] => Array
(
)
[address] =>
[expiration] => 1471667969000
[id] => 27baf74c-59d*****************
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => Ga-R5***************
[resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?key=AIzaS*********************&alt=json
[token] => 27baf74c-5****************
[type] =>
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
但是在我的通知中 url 当我的日历发生变化时我没有收到任何消息。我错过了什么吗!?在我的响应地址参数是空的。有什么问题吗?我在 google 中完成了所有 url 验证。请帮助我
您必须实施 Watch
方法。要为有关特定资源更改的消息设置通知通道,请向资源的 watch
方法发送 POST
请求。
每个通知渠道都与特定用户和特定资源相关联。除非当前用户拥有或有权访问此资源,否则观看请求不会成功。
要求:
https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
开始关注给定日历上 collection 事件的变化:
POST https://www.googleapis.com/calendar/v3/calendars/example.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}
回复:
{
"kind": "api#channel",
"id": "01234567-89ab-cdef-0123456789ab"", // ID you specified for this channel.
"resourceId": "o3hgv1538sdjfh", // ID of the watched resource.
"resourceUri": "https://www.googleapis.com/calendar/v3/calendars/example.com/events", // Version-specific ID of the watched resource.
"token": "target=myApp-myCalendarChannelDest", // Present only if one was provided.
"expiration": 1426325213000, // Actual expiration time as Unix timestamp (in ms), if applicable.
}
创建新的通知渠道来观看资源后,Google 日历 API 发送同步消息以指示通知开始。这些消息的 X-Goog-Resource-State
HTTP header 值为同步。由于网络计时问题,甚至在您收到 watch
方法响应之前就可能收到同步消息。
我正在使用 php 监视命令:
try {
$service = new Google_Service_Calendar($this->gapi->client);
$channel = new Google_Service_Calendar_Channel($this->gapi->client);
$uuid = '27baf74c-59****************';
$channel->setId($uuid);
$channel->setType('web_hook');
$channel->setToken($uuid);
$channel->setAddress('https://*********.com/calendar_webhook');
$watchEvent = $service->events->watch('primary',$channel);
print_r($watchEvent);
} catch (Exception $e) {
print_r($e->getMessage());
}
之后我收到了 $watchEvent
这样的回复Google_Service_Calendar_Channel Object
(
[internal_gapi_mappings:protected] => Array
(
)
[address] =>
[expiration] => 1471667969000
[id] => 27baf74c-59d*****************
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => Ga-R5***************
[resourceUri] => https://www.googleapis.com/calendar/v3/calendars/primary/events?key=AIzaS*********************&alt=json
[token] => 27baf74c-5****************
[type] =>
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
但是在我的通知中 url 当我的日历发生变化时我没有收到任何消息。我错过了什么吗!?在我的响应地址参数是空的。有什么问题吗?我在 google 中完成了所有 url 验证。请帮助我
您必须实施 Watch
方法。要为有关特定资源更改的消息设置通知通道,请向资源的 watch
方法发送 POST
请求。
每个通知渠道都与特定用户和特定资源相关联。除非当前用户拥有或有权访问此资源,否则观看请求不会成功。
要求:
https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
开始关注给定日历上 collection 事件的变化:
POST https://www.googleapis.com/calendar/v3/calendars/example.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}
回复:
{
"kind": "api#channel",
"id": "01234567-89ab-cdef-0123456789ab"", // ID you specified for this channel.
"resourceId": "o3hgv1538sdjfh", // ID of the watched resource.
"resourceUri": "https://www.googleapis.com/calendar/v3/calendars/example.com/events", // Version-specific ID of the watched resource.
"token": "target=myApp-myCalendarChannelDest", // Present only if one was provided.
"expiration": 1426325213000, // Actual expiration time as Unix timestamp (in ms), if applicable.
}
创建新的通知渠道来观看资源后,Google 日历 API 发送同步消息以指示通知开始。这些消息的 X-Goog-Resource-State
HTTP header 值为同步。由于网络计时问题,甚至在您收到 watch
方法响应之前就可能收到同步消息。