google 日历推送通知问题
Issue with google calendar push notification
我尝试在我的服务器中实现 google 日历推送通知。
使用 outhplayground,我能够成功订阅该服务。
当日历发生变化时,我会收到我注册的 url 的通知。
唯一的问题是我收到的响应没有数据。它是一个空响应。
谁能告诉我问题出在哪里。我在后端使用 PHP 代码来访问命中我的 url.
的请求
authplayground 代码:
POST /calendar/v3/calendars/calendarname@gmail.com/events/watch HTTP/1.1
Host: www.googleapis.com
Content-length: 161
Content-type: application/json
Authorization: Bearer access_token
{
"id": "01234267-89a6-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/response" // Your receiving URL.
}
接受请求的代码:
$json = file_get_contents('php://input');
$request = json_decode($json, true);
$post_request = $_POST;
$get_request = $_REQUEST;
当我得到一个空的响应时,我尝试编写代码来接受任何可能的方式。
Google 将 headers 中的响应作为数组发送。
试试这个:
$response = apache_request_headers();
if($response) {
print_r($response);
}else {
echo 'The apache_request_headers() did not find any headers.'; //Or google is not sending any.
}
您也可以试试:
getallheaders()
如果 apache_request_headers 不起作用。
测试这个可能很困难。您可能想要设置一个日志,将您的页面获得的任何数据发送到数据库中的 table,以便您可以返回并检查您正在取得的进展类型。
您可以获得这样的值:
$channelId = $_SERVER['HTTP_X_GOOG_CHANNEL_ID'];
$resourceId = $_SERVER['HTTP_X_GOOG_RESOURCE_ID'];
if($channelId) {
file_put_contents('webhook.txt', $channelId.' ||| '.$resourceId);
}
您可以在此处获得不同的 headers
:https://developers.google.com/calendar/v3/push#understanding-the-notification-message-format
我尝试在我的服务器中实现 google 日历推送通知。 使用 outhplayground,我能够成功订阅该服务。 当日历发生变化时,我会收到我注册的 url 的通知。 唯一的问题是我收到的响应没有数据。它是一个空响应。
谁能告诉我问题出在哪里。我在后端使用 PHP 代码来访问命中我的 url.
的请求authplayground 代码:
POST /calendar/v3/calendars/calendarname@gmail.com/events/watch HTTP/1.1
Host: www.googleapis.com
Content-length: 161
Content-type: application/json
Authorization: Bearer access_token
{
"id": "01234267-89a6-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://example.com/response" // Your receiving URL.
}
接受请求的代码:
$json = file_get_contents('php://input');
$request = json_decode($json, true);
$post_request = $_POST;
$get_request = $_REQUEST;
当我得到一个空的响应时,我尝试编写代码来接受任何可能的方式。
Google 将 headers 中的响应作为数组发送。
试试这个:
$response = apache_request_headers();
if($response) {
print_r($response);
}else {
echo 'The apache_request_headers() did not find any headers.'; //Or google is not sending any.
}
您也可以试试:
getallheaders()
如果 apache_request_headers 不起作用。
测试这个可能很困难。您可能想要设置一个日志,将您的页面获得的任何数据发送到数据库中的 table,以便您可以返回并检查您正在取得的进展类型。
您可以获得这样的值:
$channelId = $_SERVER['HTTP_X_GOOG_CHANNEL_ID'];
$resourceId = $_SERVER['HTTP_X_GOOG_RESOURCE_ID'];
if($channelId) {
file_put_contents('webhook.txt', $channelId.' ||| '.$resourceId);
}
您可以在此处获得不同的 headers
:https://developers.google.com/calendar/v3/push#understanding-the-notification-message-format