我在尝试使用google / apiclient时遇到问题
isLoggedIn()):?> (!)致命错误:在第27行的C:\ wamp \ www \ Google \ app \ class \ google_auth.php中的非对象上调用成员函数createAuthUrl()调用堆栈#TimeMemoryFunctionLocation 10.0025141744 {main}()。 。\ index.php:0 20.0979526816GoogleAuth-> getAuthUrl().. \ index.php:22
我的索引:
<?php
require_once('vendor/autoload.php');
require_once('app/class/google_auth.php');//Class
require_once('app/ini.php');
$googleClient = new Google_Client();
$auth = new GoogleAuth($googleClient);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php//Verificar Inicio de Sesion
if (!$auth->isLoggedIn()):
?>
<a href="<?php echo $auth->getAuthUrl(); ?>">Inicie Sesion con Google</a>
<?php//Si no ha iniciado Sesion
else:
?>
<a href="logout.php">Cerrar Sesion</a>
<?php//Si no ha iniciado Sesion
endif;
?>
</body>
</html>
&安培; GoogleAuth类
<?php
class GoogleAuth{
protected $client;
public function _constructor(Google_Client $googleClient = null){
$this->client = $googleClient;
if ($this->client) {
$this->client->setClientId('474251646530-tiho0cbf4d15pcb6.apps.googleusercontent.com');
$this->client->setClientSecret('bMuLusxZW6ohlI3vn');
$this->client->setRedirectUri('http://localhost/Google/index.php');
$this->client->setScopes('email');
}
}
public function isLoggedIn(){
return isset($_SESSION['access_token']);
}
public function getAuthUrl(){
return $this->client->createAuthUrl();
}
}
?>
答案 0 :(得分:0)
我认为问题在于这行代码:
$googleCliente = new Google_Client();
将其更改为:
$googleClient = new Google_Client();
这是一个非常基本的错字。你这样称呼它:
$auth = new GoogleAuth($googleClient); // notice the variable googleClient does not have an e on the end
请务必阅读您的代码。