0

我刚刚安装了一个 google auth SDK。我想在 CodeIgniter 库中应用它。

这是我的图书馆

<?php

class Chatlibrary{

    function linkauth(){

        $customConfig = (object) array(
            'clientID' => 'myIdGoogle',
            'clientSecret' => 'MySecretId',
            'redirectUri' => 'MyRedirectUri',
            'developerKey' => ''
        );

        require_once 'autoload.php';

        $google = new rapidweb\googlecontacts\helpers\GoogleHelper;

        $client = GoogleHelper::getClient($customConfig);

        $authUrl = GoogleHelper::getAuthUrl($client);

        return $authUrl;
    }

我只想rapidweb\googlecontacts\helpers\GoogleHelper正确调用。

我上面的代码会显示错误

“消息:无法实例化抽象类 rapidweb\googlecontacts\helpers\GoogleHelper”。

任何人都可以帮助我吗??

4

3 回答 3

1

只需删除该行$google = new rapidweb\googlecontacts\helpers\GoogleHelper;

这是你尝试实例化 GoogleHelper 的地方,以后你不使用 $google 变量,而是调用 GoogleHelper 的静态方法。因此,您根本不需要实例化它。

如果没有帮助,您可以执行以下操作:

1)创建自己的类

class MyGoogleHelper extends rapidweb\googlecontacts\helpers\GoogleHelper
{
 //...
}

2) 使用它代替 rapidweb\googlecontacts\helpers\GoogleHelper

3)如果您会收到有关该类的某些未实现方法的错误,请实现 whem,即使是空的也可以一开始。

于 2019-02-07T04:22:22.193 回答
1

您无法为错误的抽象类创建对象..尝试这样的事情

<?php
use rapidweb\googlecontacts\helpers\GoogleHelper;
class Chatlibrary extends GoogleHelper {

function linkauth(){

    $customConfig = (object) array(
        'clientID' => 'myIdGoogle',
        'clientSecret' => 'MySecretId',
        'redirectUri' => 'MyRedirectUri',
        'developerKey' => ''
    );

    $client = GoogleHelper::getClient($customConfig);

    $authUrl = GoogleHelper::getAuthUrl($client);

    return $authUrl;
}
于 2019-02-07T04:45:20.920 回答
1

供参考:

我们不能创建抽象类的实例。要使用抽象类的方法,我们必须在另一个类中扩展抽象类。在您的情况下,您正在尝试将抽象类实例化为

$google = new rapidweb\googlecontacts\helpers\GoogleHelper;

这是不允许的。您可以简单地在类中扩展上述类,如andChatlibrary回答的那样,您可以访问抽象类的所有方法。MihanEntalpoShibon

有关抽象类的更多信息,您可以参考PHP 手册。

于 2019-02-07T05:24:58.073 回答