<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
<!DOCTYPE html>
<!--
*********** GOOGLE CALENDAR ****************************
Author: Vanderlei Bailo
E-mail: vanbailo@gmail.com
Script: insert, change and delete Google Calenda event
https://console.developers.google.com/project/feisty-filament-107711/apiui/apiview/calendar/quotas
-->
<html>
<head>
<title>GOOGLE CALENDAR - insert, change and delete Google Calenda event</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<style>
body{
margin: 0;
width: 100%;
font-family: Verdana, Arial;
}
#centro{
width: 780px;
margin: auto;
}
.calendario{
position: relative;
width: 800px;
height: 600px;
margin-left:-390px;
left: 50%;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#datahora{
width: 250px;
float: left;
}
#cento{
width: 780px;
float: left;
}
#centro .primo{
width: 100%;
background-color: #E3E9FF;
padding: 10px;
margin: 50px 0;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
label {
width: 780px;
margin: 5px 5px 0;
float: left;
padding-top: 10px;
}
input{
margin: 5px;
float: left;
padding: 5px 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px #CCC solid;
}
input[type="text"]{
width: 750px;
}
input[type="date"]{
width: 125px;
}
input[type="time"]{
width: 70px;
}
input[type="submit"]{
}
input:focus{
border: 1px #cc0000 solid;
box-shadow: 0 0 5px #cc0000;
}
.btn {
background: #3498db;
background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
background-image: -moz-linear-gradient(top, #3498db, #2980b9);
background-image: -ms-linear-gradient(top, #3498db, #2980b9);
background-image: -o-linear-gradient(top, #3498db, #2980b9);
background-image: linear-gradient(to bottom, #3498db, #2980b9);
-webkit-border-radius: 5;
-moz-border-radius: 5;
border-radius: 5px;
font-family: Arial;
color: #ffffff;
font-size: 20px;
padding: 10px 20px 10px 20px;
text-decoration: none;
cursor: pointer;
}
.btn:hover {
background: #3cb0fd;
background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
text-decoration: none;
}
</style>
</head>
<body>
<?php
session_start();
require 'google-api-php-client-master/src/Google/autoload.php';
require_once 'google-api-php-client-master/src/Google/Client.php';
require_once 'google-api-php-client-master/src/Google/Service/Calendar.php';
$client_id = '417715593465-63mp7cfotbfjuilehttiqsv7lc2ggm4r.apps.googleusercontent.com'; //change this
$Email_address = '417715593465-rnpu25se7ho9oblam21kulifm54db2q3@developer.gserviceaccount.com'; //change this
$key_file_location = 'My Calendar-fd38d3496d1c.p12'; //change this
$client = new Google_Client();
$client->setApplicationName("My Calendar");
$key = file_get_contents($key_file_location);
$scopes = "https://www.googleapis.com/auth/calendar";
$cred = new Google_Auth_AssertionCredentials(
$Email_address, array($scopes), $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
while (true) {
//list of calender
foreach ($calendarList->getItems() as $calendarListEntry) {
echo "<a href='Oauth2.php?type=event&id=" . $calendarListEntry->id . " '>" . $calendarListEntry->getSummary() . "-ID : " . $calendarListEntry->getId() ."</a><br>\n";
//print_r($calendarListEntry);
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
//For Show Calender data BY calender id
/*date_default_timezone_set('America/New_York');
echo $start = date(DATE_ATOM,strtotime('now'));
echo $end = date(DATE_ATOM,strtotime('+1 month'));
*/
$params = array(
'singleEvents' => 'true',
//'timeMax' => $end,
//'timeMin' => $start,
'orderBy' => 'startTime');
$event_list = $service->events->listEvents('lbn95u1fkaa2quefa0i84h37dc@group.calendar.google.com', $params);
$events = $event_list->getItems();
echo '<table border="1"><thead>';
echo '<th>ID</th><th>EVENT Name</th><th>Where</th><th>Description</th><th>Start</th><th>End</th></tr></thead>';
foreach ($events as $event) {
echo '<tr>';
echo '<td>'.$event->getId().'</td>';
echo '<td>'.$event->getSummary().'</td>';
echo '<td>'.$event->getLocation().'</td>';
echo '<td>'.$event->getDescription().'</td>';
echo '<td>'.$event->getStart()->getDateTime().'</td>';
echo '<td>'.$event->getEnd()->getDateTime().'</td>';
echo '</tr>';
}
echo '</table>';
//for delete
//$service->calendars->delete('g9iujjjo9jpll8s08hb7f9o718@group.calendar.google.com');
if ($_POST['Addcal']) {
//For Create New Calender
$calendar = new Google_Service_Calendar_Calendar();
$calname=$_POST['calname'];
$calendar->setSummary($calname);
$calendar->setTimeZone('Asia/Calcutta');
$createdCalendar = $service->calendars->insert($calendar);
echo $createdCalendar->getId();
echo "<pre>";
print_r($createdCalendar);
echo "</pre>";
}
if ($_POST['Summary']) {
$Summary = $_POST['Summary'];
$Description = $_POST['Description'];
$Location = $_POST['Location'];
$DateStart = $_POST['DateStart'];
$TimeStart = $_POST['TimeStart'];
$DateEnd = $_POST['DateEnd'];
$TimeEnd = $_POST['TimeEnd'];
$acao = $_POST['acao'];
if ($acao == 'insert') {
//--------------- trying to insert EVENT ---------------
$event = new Google_Service_Calendar_Event();
$event->setSummary($Summary);
$event->setLocation($Location);
$event->setDescription($Description);
$start = new Google_Service_Calendar_EventDateTime();
$datatimeI = geratime(DataIT2DB($DateStart), $TimeStart);
$start->setDateTime($datatimeI);
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$datatimeF = geratime(DataIT2DB($DateEnd), $TimeEnd);
$end->setDateTime($datatimeF);
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('lbn95u1fkaa2quefa0i84h37dc@group.calendar.google.com');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
$_SESSION['eventID'] = $createdEvent->getId();
} else if ($acao == 'cancel') {
//--------------- trying to del EVENT ---------------
$createdEvent = $service->events->delete('primary', $_SESSION['eventID']);
} else if ($acao == 'update') {
//--------------- trying to update EVENT ---------------
$rule = $service->events->get('primary', $_SESSION['eventID']);
$event = new Google_Service_Calendar_Event();
$event->setSummary($Summary);
$event->setLocation($Location);
$start = new Google_Service_Calendar_EventDateTime();
$datatimeI = geratime(DataIT2DB($DateStart), $TimeStart);
$start->setDateTime($datatimeI);
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$datatimeF = geratime(DataIT2DB($DateEnd), $TimeEnd);
$end->setDateTime($datatimeF);
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('samrat.p@edreamz.in'); //change this
$attendees = array($attendee1);
$event->attendees = $attendees;
$updatedRule = $service->events->update('primary', $rule->getId(), $event);
}
}
function DataIT2DB($datapega) {
if ($datapega) {
$data = explode('/', $datapega);
if (count($data) > 1) {
$datacerta = $data[2] . '-' . $data[1] . '-' . $data[0];
} else {
$datacerta = $datapega;
}
} else {
$datacerta = $datapega;
}
return $datacerta;
}
function geratime($DateStart, $TimeStart) {
$dataHora = $DateStart . 'T' . $TimeStart . ':00.000+05:30'; //Fuso Rome
return $dataHora;
}
?>
<div id="contenut" style="width: 100%; float: left;">
<div id="centro">
<div class="primo">
<form name="adicionar" method="POST" action="#">
ID : <?php echo ( isset($_SESSION['eventID']) ? $_SESSION['eventID'] : "" ); ?>
<input type="hidden" name="" value="<?php echo ( isset($_SESSION['eventID']) ? $_SESSION['eventID'] : "" ); ?>" />
<input type="text" name="Summary" value="<?php echo ( isset($_POST['Summary']) ? $_POST['Summary'] : "" ); ?>" placeholder="Event Name"/>
<input type="text" name="Location" value="<?php echo ( isset($_POST['Location']) ? $_POST['Location'] : "" ); ?>" placeholder="Where "/><br>
<textarea rows="4" cols="50" name="Description">
<?php echo ( isset($_POST['Description']) ? $_POST['Description'] : "" ); ?>
</textarea><br>
<div id="datahora">
<label>Date and time of the Start</label>
<input type="date" name="DateStart" value="<?php echo ( isset($_POST['DateStart']) ? $_POST['DateStart'] : "" ); ?>" placeholder="DD/MM/YYYY"/>
<input type="time" name="TimeStart" value="<?php echo ( isset($_POST['TimeStart']) ? $_POST['TimeStart'] : "" ); ?>" placeholder="10:20"/>
</div>
<div id="datahora">
<label>Date and time of the end</label>
<input type="date" name="DateEnd" value="<?php echo ( isset($_POST['DateEnd']) ? $_POST['DateEnd'] : "" ); ?>" placeholder="DD/MM/YYYY"/>
<input type="time" name="TimeEnd" value="<?php echo ( isset($_POST['TimeEnd']) ? $_POST['TimeEnd'] : "" ); ?>" placeholder="10:20" />
</div>
<div id="cento">
<input class="btn" type="submit" value="insert" name="acao" />
<!--<input class="btn" type="submit" value="cancel" name="acao" />
<input class="btn" type="submit" value="update" name="acao" />-->
</div>
</form>
</div>
</div>
</div>
<div id="contenut" style="width: 100%; float: left;">
<div id="centro">
<div class="primo">
<form name="add" method="POST" action="#">
<input type="text" name="calname" value="" placeholder="Calender Name"/>
<div id="cento">
<input class="btn" type="submit" value="Add New Calender" name="Addcal" require/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<!--
*********** GOOGLE CALENDAR ****************************
Author: Vanderlei Bailo
E-mail: vanbailo@gmail.com
Script: insert, change and delete Google Calenda event
https://console.developers.google.com/project/feisty-filament-107711/apiui/apiview/calendar/quotas
-->
<html>
<head>
<title>GOOGLE CALENDAR - insert, change and delete Google Calenda event</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<style>
body{
margin: 0;
width: 100%;
font-family: Verdana, Arial;
}
#centro{
width: 780px;
margin: auto;
}
.calendario{
position: relative;
width: 800px;
height: 600px;
margin-left:-390px;
left: 50%;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#datahora{
width: 250px;
float: left;
}
#cento{
width: 780px;
float: left;
}
#centro .primo{
width: 100%;
background-color: #E3E9FF;
padding: 10px;
margin: 50px 0;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
label {
width: 780px;
margin: 5px 5px 0;
float: left;
padding-top: 10px;
}
input{
margin: 5px;
float: left;
padding: 5px 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px #CCC solid;
}
input[type="text"]{
width: 750px;
}
input[type="date"]{
width: 125px;
}
input[type="time"]{
width: 70px;
}
input[type="submit"]{
}
input:focus{
border: 1px #cc0000 solid;
box-shadow: 0 0 5px #cc0000;
}
.btn {
background: #3498db;
background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
background-image: -moz-linear-gradient(top, #3498db, #2980b9);
background-image: -ms-linear-gradient(top, #3498db, #2980b9);
background-image: -o-linear-gradient(top, #3498db, #2980b9);
background-image: linear-gradient(to bottom, #3498db, #2980b9);
-webkit-border-radius: 5;
-moz-border-radius: 5;
border-radius: 5px;
font-family: Arial;
color: #ffffff;
font-size: 20px;
padding: 10px 20px 10px 20px;
text-decoration: none;
cursor: pointer;
}
.btn:hover {
background: #3cb0fd;
background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
text-decoration: none;
}
</style>
</head>
<body>
<?php
session_start();
require 'google-api-php-client-master/src/Google/autoload.php';
require_once 'google-api-php-client-master/src/Google/Client.php';
require_once 'google-api-php-client-master/src/Google/Service/Calendar.php';
$client_id = '417715593465-63mp7cfotbfjuilehttiqsv7lc2ggm4r.apps.googleusercontent.com'; //change this
$Email_address = '417715593465-rnpu25se7ho9oblam21kulifm54db2q3@developer.gserviceaccount.com'; //change this
$key_file_location = 'My Calendar-fd38d3496d1c.p12'; //change this
$client = new Google_Client();
$client->setApplicationName("My Calendar");
$key = file_get_contents($key_file_location);
$scopes = "https://www.googleapis.com/auth/calendar";
$cred = new Google_Auth_AssertionCredentials(
$Email_address, array($scopes), $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
while (true) {
//list of calender
foreach ($calendarList->getItems() as $calendarListEntry) {
echo "<a href='Oauth2.php?type=event&id=" . $calendarListEntry->id . " '>" . $calendarListEntry->getSummary() . "-ID : " . $calendarListEntry->getId() ."</a><br>\n";
//print_r($calendarListEntry);
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
//For Show Calender data BY calender id
/*date_default_timezone_set('America/New_York');
echo $start = date(DATE_ATOM,strtotime('now'));
echo $end = date(DATE_ATOM,strtotime('+1 month'));
*/
$params = array(
'singleEvents' => 'true',
//'timeMax' => $end,
//'timeMin' => $start,
'orderBy' => 'startTime');
$event_list = $service->events->listEvents('lbn95u1fkaa2quefa0i84h37dc@group.calendar.google.com', $params);
$events = $event_list->getItems();
echo '<table border="1"><thead>';
echo '<th>ID</th><th>EVENT Name</th><th>Where</th><th>Description</th><th>Start</th><th>End</th></tr></thead>';
foreach ($events as $event) {
echo '<tr>';
echo '<td>'.$event->getId().'</td>';
echo '<td>'.$event->getSummary().'</td>';
echo '<td>'.$event->getLocation().'</td>';
echo '<td>'.$event->getDescription().'</td>';
echo '<td>'.$event->getStart()->getDateTime().'</td>';
echo '<td>'.$event->getEnd()->getDateTime().'</td>';
echo '</tr>';
}
echo '</table>';
//for delete
//$service->calendars->delete('g9iujjjo9jpll8s08hb7f9o718@group.calendar.google.com');
if ($_POST['Addcal']) {
//For Create New Calender
$calendar = new Google_Service_Calendar_Calendar();
$calname=$_POST['calname'];
$calendar->setSummary($calname);
$calendar->setTimeZone('Asia/Calcutta');
$createdCalendar = $service->calendars->insert($calendar);
echo $createdCalendar->getId();
echo "<pre>";
print_r($createdCalendar);
echo "</pre>";
}
if ($_POST['Summary']) {
$Summary = $_POST['Summary'];
$Description = $_POST['Description'];
$Location = $_POST['Location'];
$DateStart = $_POST['DateStart'];
$TimeStart = $_POST['TimeStart'];
$DateEnd = $_POST['DateEnd'];
$TimeEnd = $_POST['TimeEnd'];
$acao = $_POST['acao'];
if ($acao == 'insert') {
//--------------- trying to insert EVENT ---------------
$event = new Google_Service_Calendar_Event();
$event->setSummary($Summary);
$event->setLocation($Location);
$event->setDescription($Description);
$start = new Google_Service_Calendar_EventDateTime();
$datatimeI = geratime(DataIT2DB($DateStart), $TimeStart);
$start->setDateTime($datatimeI);
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$datatimeF = geratime(DataIT2DB($DateEnd), $TimeEnd);
$end->setDateTime($datatimeF);
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('lbn95u1fkaa2quefa0i84h37dc@group.calendar.google.com');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
$_SESSION['eventID'] = $createdEvent->getId();
} else if ($acao == 'cancel') {
//--------------- trying to del EVENT ---------------
$createdEvent = $service->events->delete('primary', $_SESSION['eventID']);
} else if ($acao == 'update') {
//--------------- trying to update EVENT ---------------
$rule = $service->events->get('primary', $_SESSION['eventID']);
$event = new Google_Service_Calendar_Event();
$event->setSummary($Summary);
$event->setLocation($Location);
$start = new Google_Service_Calendar_EventDateTime();
$datatimeI = geratime(DataIT2DB($DateStart), $TimeStart);
$start->setDateTime($datatimeI);
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$datatimeF = geratime(DataIT2DB($DateEnd), $TimeEnd);
$end->setDateTime($datatimeF);
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('samrat.p@edreamz.in'); //change this
$attendees = array($attendee1);
$event->attendees = $attendees;
$updatedRule = $service->events->update('primary', $rule->getId(), $event);
}
}
function DataIT2DB($datapega) {
if ($datapega) {
$data = explode('/', $datapega);
if (count($data) > 1) {
$datacerta = $data[2] . '-' . $data[1] . '-' . $data[0];
} else {
$datacerta = $datapega;
}
} else {
$datacerta = $datapega;
}
return $datacerta;
}
function geratime($DateStart, $TimeStart) {
$dataHora = $DateStart . 'T' . $TimeStart . ':00.000+05:30'; //Fuso Rome
return $dataHora;
}
?>
<div id="contenut" style="width: 100%; float: left;">
<div id="centro">
<div class="primo">
<form name="adicionar" method="POST" action="#">
ID : <?php echo ( isset($_SESSION['eventID']) ? $_SESSION['eventID'] : "" ); ?>
<input type="hidden" name="" value="<?php echo ( isset($_SESSION['eventID']) ? $_SESSION['eventID'] : "" ); ?>" />
<input type="text" name="Summary" value="<?php echo ( isset($_POST['Summary']) ? $_POST['Summary'] : "" ); ?>" placeholder="Event Name"/>
<input type="text" name="Location" value="<?php echo ( isset($_POST['Location']) ? $_POST['Location'] : "" ); ?>" placeholder="Where "/><br>
<textarea rows="4" cols="50" name="Description">
<?php echo ( isset($_POST['Description']) ? $_POST['Description'] : "" ); ?>
</textarea><br>
<div id="datahora">
<label>Date and time of the Start</label>
<input type="date" name="DateStart" value="<?php echo ( isset($_POST['DateStart']) ? $_POST['DateStart'] : "" ); ?>" placeholder="DD/MM/YYYY"/>
<input type="time" name="TimeStart" value="<?php echo ( isset($_POST['TimeStart']) ? $_POST['TimeStart'] : "" ); ?>" placeholder="10:20"/>
</div>
<div id="datahora">
<label>Date and time of the end</label>
<input type="date" name="DateEnd" value="<?php echo ( isset($_POST['DateEnd']) ? $_POST['DateEnd'] : "" ); ?>" placeholder="DD/MM/YYYY"/>
<input type="time" name="TimeEnd" value="<?php echo ( isset($_POST['TimeEnd']) ? $_POST['TimeEnd'] : "" ); ?>" placeholder="10:20" />
</div>
<div id="cento">
<input class="btn" type="submit" value="insert" name="acao" />
<!--<input class="btn" type="submit" value="cancel" name="acao" />
<input class="btn" type="submit" value="update" name="acao" />-->
</div>
</form>
</div>
</div>
</div>
<div id="contenut" style="width: 100%; float: left;">
<div id="centro">
<div class="primo">
<form name="add" method="POST" action="#">
<input type="text" name="calname" value="" placeholder="Calender Name"/>
<div id="cento">
<input class="btn" type="submit" value="Add New Calender" name="Addcal" require/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Comments
Post a Comment