I'm trying to configure OAuth for mine Calendar API.
My customer need in his website a forms that can INSERT
, DELETE
and UPDATE
in his database and in his Google Calendar, using the API.
Database is all fine, but I can't handle this OAuth authentication..
Source code .PHP:
<?php
include('../lib/config.php');
include('../lib/check_session.php');
$appoinment_id=$_REQUEST['appoinment_id'];
$caption="Création D'un";
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Insert & Update Query
if($_POST['Submit'])
{
if($appoinment_id)
{
$sqlUpdate = "UPDATE `tbl_appoinment` SET
appoinment_date='".$_POST['appoinment_date']."' ,
appoinment_time='".$_POST['appoinment_time']."' ,
appoinment_for='".$_POST['appoinment_for']."' ,
appoinment_customer_name='".$_POST['appoinment_customer_name']."' ,
appoinment_customer_phone='".$_POST['appoinment_customer_phone']."',
appoinment_comment='".$_POST['appoinment_comment']."',
appoinment_email='".$_POST['appoinment_email']."',
appoinment_message='".$_POST['appoinment_message']."',
appoinment_status='A'
WHERE appoinment_id='".$appoinment_id."'";
$queryUpdate = mysql_query($sqlUpdate) or die(mysql_error());
echo '<script>window.location.href="manage_appoinment.php?client_id='.$client_id.'"</script>';
}
else
{
$date = $_POST['appoinment_date'];
$time = $_POST['appoinment_time'];
$datetime = $date . "T" . $time . ".000+01:00";
require __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Calendar API');
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
define('SCOPES', implode(' ', array(Google_Service_Calendar::CALENDAR)));
session_start();
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/');
$cal = new Google_Service_Calendar($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$event = new Google_Service_Calendar_Event(array(
'summary' => $_POST['appoinment_customer_name'],
'location' => $_POST['appoinment_for'],
'description' => $_POST['appoinment_comment'],
'start' => array(
'dateTime' => $datetime,
'timeZone' => 'France/Paris'
),
'end' => array(
'dateTime' => $datetime,
'timeZone' => 'France/Paris'
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'reminders' => array(
'useDefault' => FALSE, //IF YOU DON'T WANT NOTIFICATION set TRUE
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
)
));
$createdEvent = $cal->events->insert('ikov306928o4ku82hul014904o@group.calendar.google.com', $event);
$_SESSION['token'] = $client->getAccessToken();
callSQL();
function callSQL()
{
$sqlInsert = "INSERT INTO `tbl_appoinment` SET
appoinment_date='".$_POST['appoinment_date']."' ,
appoinment_time='".$_POST['appoinment_time']."' ,
appoinment_for='".$_POST['appoinment_for']."' ,
appoinment_customer_name='".$_POST['appoinment_customer_name']."' ,
appoinment_customer_phone='".$_POST['appoinment_customer_phone']."',
appoinment_comment='".$_POST['appoinment_comment']."',
appoinment_email='".$_POST['appoinment_email']."',
appoinment_message='".$_POST['appoinment_message']."',
appointment_CalendarID='".$createdEvent->id."',
appoinment_status='A'";
$queryInsert = mysql_query($sqlInsert) or die(mysql_error());
$Insertid=mysql_insert_id();
echo '<script>window.location.href="manage_appoinment.php?appoinment_id='.$Insertid.'"</script>';
}
}
else
{
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
}
}
if($appoinment_id)
{
$caption="Modifier";
$sqlxCoGGunt = "SELECT * FROM `tbl_appoinment` WHERE appoinment_id='".$appoinment_id."' ";
$sqlCQuKKer = mysql_query($sqlxCoGGunt) or die(mysql_error());
$fetch = mysql_fetch_array($sqlCQuKKer);
}
?>
<?php include('header.php'); ?>
<?php include('menu.php'); ?>
<link rel="stylesheet" href="js/time_picker/include/jquery-ui-1.8.14.custom.css" type="text/css" />
<style type="text/css">
.ui-widget-header {
color:#F6AD36 !important;
}
</style>
<script type="text/javascript" src="js/time_picker/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/time_picker/include/jquery.ui.position.min.js"></script>
<script type="text/javascript" src="js/time_picker/jquery.ui.timepicker.js?v=0.2.4"></script>
<script src="js/datepicker-fr.js"></script>
<script language="javascript">
$(document).ready(function() {
$("#appoinment_date").datepicker({
yearRange: '1909:2100' ,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
showAnim: 'fadeIn',
duration: 1,
},
$.datepicker.regional[ "fr" ]);
$("#appoinment_time").timepicker({
yearRange: '1909:2100' ,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
showAnim: 'fadeIn',
duration: 1,
},
$.datepicker.regional[ "fr" ]);
$('#ui-datepicker-div').hide();
});
</script>
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h2>Manage Appoinment</h2>
</div>
</div>
<!-- /. ROW -->
<hr />
<!-- Start Tables -->
<div class="panel panel-default">
<!--<div class="panel-heading">Annonce:</div>-->
<div class="panel-body">
<?php if(!empty($_GET['msg']) && $_GET['msg']=="success"){?>
<div class="alert alert-success">
<?php echo UPDATE; ?>
</div>
<?php } ?>
<?php if(!empty($_GET['msg']) && $_GET['msg']=="error"){?>
<div class="alert alert-danger">
<?php echo USER_EXIST; ?>
</div>
<?php } ?>
<div class="table-responsive">
<form name="form1" id="form1" action="" method="post">
<table class="table table-striped">
<tr>
<td width="20%"><strong>Date de rendez vous:</strong></td>
<td width="30%"><input type="text" name="appoinment_date" id="appoinment_date" value="<?php echo $fetch['appoinment_date'];?>" validate="{required:true,messages:{required:'Please enter date de appoinment.'}}" class="form-control" />
</td>
<td colspan="2"> </td>
</tr>
<tr><td colspan="4"> </td></tr>
<tr>
<td width="20%"><strong>Heure de rendez vous:</strong></td>
<td width="30%"><input type="text" name="appoinment_time" id="appoinment_time" value="<?php echo $fetch['appoinment_time'];?>" validate="{required:true,messages:{required:'Please enter Temps appoinment.'}}" class="form-control" />
</td>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>Rendez Vous pour:</strong></td>
<td width="30%"><input type="text" name="appoinment_for" id="appoinment_for" value="<?php echo $fetch['appoinment_for'];?>" placeholder="Pour appoinment..." class="form-control" validate="{required:true,messages:{required:'Please enter Pour appoinment.'}}" /></td>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>Nom du client:</strong></td>
<td width="30%"><input type="text" name="appoinment_customer_name" id="appoinment_customer_name" value="<?php echo $fetch['appoinment_customer_name'];?>" placeholder="Nom du client..." validate="{required:true,messages:{required:'Please enter Nom du client.'}}" class="form-control" /></td>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>Numéro Téléphone Client:</strong></td>
<td width="30%"><input type="text" name="appoinment_customer_phone" id="appoinment_customer_phone" value="<?php echo $fetch['appoinment_customer_phone'];?>" placeholder="clientèle Téléphone..." validate="{required:true,messages:{required:'Please enter clientèle Téléphone.'}}" class="form-control" /></td>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>commentaire:</strong></td>
<td width="30%"><input type="text" name="appoinment_comment" id="appoinment_comment" value="<?php echo $fetch['appoinment_comment'];?>" placeholder="commentaire..." class="form-control" validate="{required:true,messages:{required:'Please enter commentaire.'}}" /></td>
<td colspan="2"> </td>
</tr>
<tr><td colspan="4"> </td></tr>
<tr>
<td><strong>Email:</strong></td>
<td width="30%"><input type="email" name="appoinment_email" id="appoinment_email" value="<?php echo $fetch['appoinment_email'];?>" placeholder="Email..." class="form-control" validate="{required:true,email:true,messages:{required:'Please enter Email.'}}" /></td>
<td colspan="2"> </td>
</tr>
<tr><td colspan="4"> </td></tr>
<tr>
<td><strong>Message:</strong></td>
<td colspan="2" width="30%"><textarea name="appoinment_message" id="appoinment_message" placeholder="Message..." class="form-control" validate="{required:true,messages:{required:'Please enter Message.'}}"><?php echo $fetch['appoinment_message'];?></textarea></td>
<td> </td>
</tr>
<tr><td colspan="4"> </td></tr>
<tr>
<td valign="top" colspan="4" style="padding:4px; text-align:center;">
<input type="submit" name="Submit" value="Enregistrer" class="btn btn-lg btn-success" >
<a href="all_appoinment.php"><input type="button" name="View" value="Retour" class="btn btn-lg btn-warning" ></a>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<!--End Tables -->
</div>
<!-- /. page-inner -->
</div>
<!-- /. page-wrapper -->
</div>
<!-- /. wrapper -->
<?php include('footer.php'); ?>
</body>
</html>
It's giving me error:
400. That’s an error.
Error: redirect_uri_mismatch
A native application: Calendar API