0

I have the following code :

$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);

How ever i am getting the unauthorized url error. I have registered my site in the search console and it is showing it in the home page of the search console page. I am not able to identify the error here.

Vivek Cu
  • 127
  • 1
  • 2
  • 9
  • Chek if you have added the domain in the Domain Verification, see related [SO post](https://stackoverflow.com/a/24588802/5995040) for details. Also you should have a valid SSL certificate installed on your web server base from the [documentation](https://developers.google.com/calendar/v3/push#making-watch-requests). Hope this helps. – Mr.Rebot Mar 13 '18 at 16:47
  • @Mr.Rebot I have added the domain in the verification and it is verified. I have the SSL certificates installed into the server. Still no luck – Vivek Cu Mar 14 '18 at 04:07

0 Answers0