我已将我的网络应用程序与谷歌登录集成。当我在核心php运行时,一切正常,但它不能在yii框架中使用相同的代码。我在跑步时遇到以下错误,
Google_Service_Exception
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
控制器
require_once Yii::app()->basePath . '/extensions/GoogleAPI/vendor/autoload.php';
public function actionIndex()
{
// echo Yii::app()->request->basePath; exit;
$gClient = new Google_Client();
$gClient->setClientId(".....");
$gClient->setClientSecret(".....");
$gClient->setApplicationName("Omega");
$gClient->setRedirectUri("http://localhost/project/index.php/site/GoogleLogin");
$gClient->addScope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email");
$loginURL = $gClient->createAuthUrl();
$this->render('index',array('loginURL'=>$loginURL));
}
//Redirecting function
public function actionGoogleLogin()
{
$googleClient= new Google_Client();
$oAuth = new Google_Service_Oauth2($googleClient);
$userData = $oAuth->userinfo_v2_me->get();
print_r($userData); exit;
}
查看页面
<a href="#" class="btn-google m-b-0" onclick="window.location = '<?php echo $loginURL ?>';">
<i class="fa fa-google"></i>
Google
</a>