我是Laravel新人Laravel 4 - Google登錄
我正在測試Google通過遵循指南使用oauth-4-laravel進行登錄。我成功地選擇我的谷歌帳戶,但之後它返回喜歡的網址:
我該如何處理我的Route.php內這條路文件?我對Route.php當前的代碼是:
Route::get('login', function()
{
return View::make('login');
});
Route::controller('google', 'GoogleController');
而且我GoogleController.php代碼
public function postLoginwithgoogle(){
// get data from input
$code = Input::get('code');
// get google service
$googleService = OAuth::consumer('Google');
// check if code is valid
// if code is provided get user data and sign in
if (!empty($code)) {
// This was a callback request from google, get the token
$token = $googleService->requestAccessToken($code);
// Send a request with it
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message. "<br/>";
//Var_dump
//display whole array().
dd($result);
}
// if not ask for permission first
else {
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to facebook login url
return Redirect::to((string)$url);
}
}
我懷疑是「後」和「得到」,但我應該怎麼編寫呢?謝謝!