1
ユーザーシステムにgoogle apiを使用するWebアプリケーションを作成しようとしています。ここで Googleの現在のユーザーをルートにログオンさせ続ける
$app->get('/home', function() use($client,$app){
if(isset($_GET['code'])){
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if(!isset($_SESSION['token'])){
$url = $client->createAuthUrl();
$output = '<a href="'.$url.'">Se connecter </a>';
} else {
$client->setAccessToken($_SESSION['token']);
$token = json_decode($_SESSION['token']['access_token']);
$output = "";
require "../view/planning.php";
}
return $output;
});
が私の$クライアントです:
実は、私は唯一のルートに自分のGoogleアカウントを接続することができ、ここにある
$client = new Google_Client();
$client->setApplicationName("Application de test");
$client->setClientId(MY_CLIENT_ID);
$client->setClientSecret(MY_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/calendar.readonly');
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->setRedirectUri(MY_REDIRECT_URI);
$client->setAccessType('online');
そして、私の質問は:私は続けることができる方法アプリケーション全体に現在のクライアント?このルートが機能していない
$app->get('/accueil', function() use($client){
if(isset($_GET['code'])){
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if(!isset($_SESSION['token'])){
$url = $client->createAuthUrl();
$output = '<a href="'.$url.'">Se connecter </a>';
} else {
$client->setAccessToken($_SESSION['token']);
$token = json_decode($_SESSION['token']['access_token']);
require ('../view/accueil.php');
$output = "";
}
return $output;
});
しかし、それは私にログインするためのリンクを表示:私はこのルートを持っている場合exempleについては 、。私はアプリケーションが何もないので、URLから'code'
を得ることができないことを理解します。
私はまた、このよう'code'
を維持しようとした:
if(isset($_GET['code']) || isset($_SESSION['code'])){
$client->authenticate($_GET['code']);
$_SESSION['code'] = $_GET['code'];
$_SESSION['token'] = $client->getAccessToken();
}
は、どのように私は、ユーザーがログインしておくことができますか?
セッションに '' code''を入れてください。 – mega6382
別のルートにアクセスしているときに$ _SESSION変数が存在しないようです。 – AdrienG