function create_calendar_event($token , $description, $leaveDate , $toLeaveDate ){
try{
$title = 'Leave today';
$start_time = '00:00'; $end_time = '23:59';
$timezone = 'Asia/Kolkata';
$start = array(
"dateTime" => $leaveDate . "T" . $start_time . ":00",
"timeZone" => $timezone
);
$end = array(
"dateTime" => $toLeaveDate . "T" . $end_time . ":00",
"timeZone" => $timezone
);
$headerarray = array(
'Content-type: application/json',
'Authorization: Bearer ' . $token->access_token,
'X-JavaScript-User-Agent: Google APIs Explorer'
);
$post_data = array(
"start" => $start,
"end" => $end,
"summary" => $title,
"description" => $description
);
$post_data = json_encode($post_data);
$calendar_id = 'primary';
$result = $this->curlRequest($url, $headerarray, $post_data);
return $result;
}catch(Exception $e){
// Exception
}
}
function curlRequest($url,$headerarray,$post_data, $curl_call = true){
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerarray);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($server_output, 0, $header_size);
$response = substr($server_output, $header_size);
$data = array();
if($info['http_code'] == 200) {
$data['headers'] = $headers;
$data['response'] = json_decode($response);
$data['status'] = 'SUCCESS';
} else {
if($info['http_code'] == 404) {
$data['response'] = 'Not Found';
$data['status'] = 'ERROR';
} else {
$data['response'] = json_decode($response);
$data['status'] = 'ERROR';
}
$data['headers'] = $headers;
}
curl_close($ch);
return $data;
} catch (Exception $e) {
// Exception
}
}