Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php (!)致命错误:调用成员函数createAuthUrl()_Php_Api_Login_Google Client - Fatal编程技术网

Php (!)致命错误:调用成员函数createAuthUrl()

Php (!)致命错误:调用成员函数createAuthUrl(),php,api,login,google-client,Php,Api,Login,Google Client,我在尝试使用google/apiclient时遇到问题 isLoggedIn()):?>(!)致命错误:在C:\wamp\www\Google\app\class\Google#auth.php的第27行调用堆栈#TimeMemoryFunctionLocation 10.0025141744{main}()..\index.php:0 20.0979526816GoogleAuth->getAuthUrl()..\index.php:22 我的索引: <?php require

我在尝试使用google/apiclient时遇到问题

isLoggedIn()):?>(!)致命错误:在C:\wamp\www\Google\app\class\Google#auth.php的第27行调用堆栈#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>

&这个班的学生是古格洛斯

<?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();

        }
    }

?>

我认为问题在于这一行代码:

$googleCliente = new Google_Client();
将其更改为:

$googleClient = new Google_Client();
这是一个非常基本的打字错误。你这样称呼它:

$auth = new GoogleAuth($googleClient); // notice the variable googleClient does not have an e on the end

一定要校对你的代码。

do
print\r($this->cliente)
$this->cliente=$googleClient之后
查看它是否保留
NULL
或者它是否分配类
Google\u Client
如果
$this->Client
将被要求使用,那么1)您不应该允许赋予它值的构造函数的参数是可选的,2)如果
$this->client
不是必需的对象Nothinghappend@jocednieves做
var\u dump($this->client)
而不是
print\u r
,因为
print\u r
什么都没做,而
var\u dump
实际打印出来它是空的。在哪里?因为我把