iT邦幫忙

0

Google API 問題

  • 分享至 

  • xImage

連結: https://developers.google.com/calendar/v3/reference/calendars/get

我已經架設好登入的系統了,現在要導入Calendar API 。Authorization 也已經有設置https://www.googleapis.com/auth/calendar ,
目前卡在GET https://www.googleapis.com/calendar/v3/calendars/calendarId 不知道要放在哪裡,不知道怎麼使用。有用過這部分的高手可以幫幫我嗎?

config.php

<?php
    session_start();
    require_once "../GoogleAPI2.2.0/vendor/autoload.php";
    $gClient = new Google_client();     //實體化類別物件
    $gClient -> setClientId("706378215405-nfk20a7s43nso9gmq.apps.googleusercontent.com");    //用戶端 ID
    $gClient -> setClientSecret("giLjSSziEEVYw1L-B");                                                //用戶端密碼
    $gClient -> setRedirectUri("http://localhost:8080/htdocs/google/login/g-callback.php");            //取得授權後要導向的網址   
    $gClient -> addScope("https://www.googleapis.com/auth/plus.login");                                     //取得登入資料
    $gClient -> addScope("https://www.googleapis.com/auth/userinfo.email");                                 //取得使用者信箱    
    $gClient -> addScope("https://www.googleapis.com/auth/calendar");
?>

g-callback.php

<?php
    require_once "config.php";
    require_once "../connctions/connect.php";
    //include "IP.php";   //抓取IP
    session_start();

    date_default_timezone_set("Asia,Taipei"); //設定時區
    
    if(isset($_SESSION['access_token'])){
        $token = $gClient->setAccessToken($_SESSION['access_token']);
    }else if(isset($_GET['code'])){
        $token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);
        $_SESSION['access_token'] = $token;
    }else{
        header('Location:login.php');
        exit();    
    }

    $oAuth = new Google_Service_Oauth2($gClient);       //實體化類別物件
    $userData = $oAuth->userinfo_v2_me->get();          //取得使用者資料


    echo "<pre>";

    var_dump($userData);    //印出使用者資料

    $_SESSION['id'] = $userData['id'];
    $_SESSION['email'] = $userData['email'];
    $_SESSION['gender'] = $userData['gender'];
    $_SESSION['picture'] = $userData['picture'];
    $_SESSION['name'] = $userData['name'];
    $_SESSION['locale'] = $userData['locale'];  //zh-TW
    $_SESSION['IP'] = $ip;

    $sql_check = "SELECT `member_google_id`,`member_id` FROM `member` WHERE `member_google_id` = '{$_SESSION['id']}' ";
    $result_check = mysqli_query($link,$sql_check);
    $row_num_check = mysqli_num_rows($result_check);
    $row_fetch_assoc = mysqli_fetch_assoc($result_check);


    if($row_num_check <= 0 ){       //確認是否有此會員
        $date = date("Y-m-d H:i:s");
        $sql_new_member = "INSERT INTO `member`(`member_google_id`,`member_google_name`,`member_email`,`member_picture`,`member_language`,`member_join_date`) 
        VALUE ('{$_SESSION['id']}','{$_SESSION['name']}','{$_SESSION['email']}','{$_SESSION['picture']}','{$_SESSION['locale']}','{$date}')";
        $result_new_member = mysqli_query($link,$sql_new_member);
        $_SESSION['member_id'] = mysqli_insert_id($link);    //取得匯入當前member_id
    }else{
        $_SESSION['member_id'] = $row_fetch_assoc['member_id'];
         
        //載入追蹤清單
        if($_SESSION['room_track'] == null){
            $sql_track = "SELECT `track_room_id` FROM `member_track_room` WHERE `member_id` = '{$_SESSION['member_id']}'";
            $result_track = mysqli_query($link,$sql_track);
            $row_track = mysqli_fetch_assoc($result_track);
            $i = 0;
            $array_list = array();
            do{
                $array_list[$i] = $row_track['track_room_id'];
                $i++;
            }while($row_track = mysqli_fetch_assoc($result_track));
            $_SESSION['room_track'] = $array_list;
        }

    }
    //date("Y-m-d",mktime(0,0,0,$months,$days+10,$years))   往後退算時間

    
    //header('Location:'.$_SESSION['url']);   //用login.php紀錄的SESSION,回到登入前的頁面
    
    exit();    
?>

<?php mysqli_close($link) ?>
<?php mysqli_free_result($result_check) ?>
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答