谷歌日历观看通知获得通知

时间:2016-06-10 08:03:13

标签: google-calendar-api google-api-php-client

您好已在谷歌日历上设置观看

$channelID = "my-caledar-".  date('His',  time()); 
$channel->setId($channelID);
$channel->setType('web_hook');
$channel->setAddress('xxxxx');

并在调用此方法后获取有效参数

当我在日历上创建/删除任何事件时,我在推送通知网址

上显示为空
if($_POST){
$msg = json_encode($_POST);
pg_query($pg_conn, "INSERT INTO postdata(post_data) values ('$msg')");
} else {
  $result = pg_query($pg_conn, "SELECT * FROM postdata;");
}

$结果变空

1 个答案:

答案 0 :(得分:1)

通知作为 POST参数,我们可以通过$ _SERVER变量来获取它

$msg = json_encode(array('HTTP_X_GOOG_CHANNEL_ID' =>  $_SERVER['HTTP_X_GOOG_CHANNEL_ID'],
'HTTP_X_GOOG_CHANNEL_EXPIRATION' => $_SERVER['HTTP_X_GOOG_CHANNEL_EXPIRATION'],
'HTTP_X_GOOG_RESOURCE_STATE' => $_SERVER['HTTP_X_GOOG_RESOURCE_STATE'],
'HTTP_X_GOOG_MESSAGE_NUMBER' => $_SERVER['HTTP_X_GOOG_MESSAGE_NUMBER'],
'HTTP_X_GOOG_RESOURCE_ID' => $_SERVER['HTTP_X_GOOG_RESOURCE_ID'],
'HTTP_X_GOOG_RESOURCE_URI' => $_SERVER['HTTP_X_GOOG_RESOURCE_URI']
));