gpt4 book ai didi

php - 谷歌日历的推送通知不起作用

转载 作者:行者123 更新时间:2023-12-04 17:57:35 26 4
gpt4 key购买 nike

我正在使用 php watch 命令:

 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 中,当我的日历发生变化时,我没有收到任何消息。我错过了什么!?在我的响应中,地址参数为空。有什么问题吗。我已经在谷歌中完成了所有的 url 验证。请帮我

最佳答案

您必须实现 Watch 方法。要为有关特定资源更改的消息设置通知 channel ,请向资源的 POST 方法发送 watch 请求。

每个通知 channel 都与特定用户和特定资源相关联。除非当前用户拥有或有权访问此资源,否则观看请求不会成功。

要求:

https://www.googleapis.com/apiName/apiVersion/resourcePath/watch

开始观察给定日历上一系列事件的变化:
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.
}

创建新的通知 channel 以观看资源后,Google 日历 API 会发送一条同步消息以指示通知正在启动。这些消息的 X-Goog-Resource-State HTTP header 值是同步的。由于网络时间问题,甚至可能在您收到 watch 方法响应之前就收到同步消息。

关于php - 谷歌日历的推送通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38929512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com