douzhang6646 2016-01-22 22:23
浏览 63
已采纳

Google Calendar API OAuth错误400 PHP

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">&nbsp;</td>
                                </tr>       
                                <tr><td colspan="4">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</td>                         
                                </tr>
                                <tr><td colspan="4">&nbsp;</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">&nbsp;</td>                         
                                </tr>
                                <tr><td colspan="4">&nbsp;</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>&nbsp;</td>                         
                                </tr>
                                <tr><td colspan="4">&nbsp;</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" > &nbsp;&nbsp;&nbsp;&nbsp;
                                        <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
  • 写回答

1条回答 默认 最新

  • dopuzf0898 2016-01-25 00:27
    关注

    It looks like your OAuth client is misconfigured. In the Credentials section of the Google Developers Console, make sure you have created a Web OAuth Client and entered an "Authorized redirect URI" that matches the value you pass in your setRedirectUri method. See this example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀