google Calendar

53 views
Skip to first unread message

Thamotharakannan Ganeshan

unread,
Feb 8, 2017, 9:03:18 AM2/8/17
to Google App Engine
Hi 
google Calendar event can't insert
my code
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';
$url = 'https://www.googleapis.com/calendar/v3/calendars/' . $calendar_id . '/events';
$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
}
}

Nick (Cloud Platform Support)

unread,
Feb 8, 2017, 7:34:50 PM2/8/17
to Google App Engine
Hey Thamotharakannan,

Unfortunately, this forum is not intended for this style of post, asking for 1-on-1 technical support on a specific issue. This forum is meant more for high level and general discussion of the platform and services of App Engine.

You should post your code to Stack Overflow (where there are many more users who are happy to answer a question in this format) along with an explanation of how you are running the code (what kind of environment is it deployed to?) and very important to include, what the actual error message you saw was.

When you post to Stack Overflow, feel free to post here with a link to the question and I'll be happy to take a look. 

Cheers,

Nick
Cloud Platform Community Support
Reply all
Reply to author
Forward
0 new messages