实施日历的谷歌推送通知有问题

时间:2018-03-13 05:41:20

标签: php google-calendar-api

我有以下代码:

$url = sprintf("https://www.googleapis.com/calendar/v3/calendars/calendarname/events/watch");
/* setup the POST parameters */
$fields = json_encode(array(
'id'        => "012345423-2ab-cdef-01345232789ab",
'type'      => "web_hook",
'address'   => sprintf("https://mysite/response/")
));
$access_token = 'access-token';
/* setup POST headers */
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $access_token;

/* send POST request */
$channel = curl_init();
curl_setopt($channel, CURLOPT_HTTPHEADER, $headers);
curl_setopt($channel, CURLOPT_URL, $url);
curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt($channel, CURLOPT_POST, true);
curl_setopt($channel, CURLOPT_POSTFIELDS, $fields);
curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($channel, CURLOPT_TIMEOUT, 3);
$response = curl_exec($channel);
curl_close($channel);

print_r($response);

我怎么会收到未经授权的网址错误。我已在搜索控制台中注册了我的网站,并在搜索控制台页面的主页上显示了该网站。我无法在此处识别错误。

0 个答案:

没有答案