从上下文调用私有方法 Kreait\Firebase\ServiceAccount::fromArray()

Call to private method Kreait\Firebase\ServiceAccount::fromArray() from context

我在我的 Laravel 应用程序中使用 Krait\Firebase 包版本 5.0.6 并尝试连接 Firebase 我遇到了这个错误: 从上下文调用私有方法 Krait\Firebase\ServiceAccount::fromArray()... 有解决办法吗? 这是我的连接代码

<?php

namespace App\Services;

use Exception;
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\Database;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Exception\Auth\EmailExists as FirebaseEmailExists;

class FirebaseService
{

    /**
     * @var Firebase
     */
    protected $firebase;

    public function __construct()
    {
        $serviceAccount = ServiceAccount::fromArray([
            "type" => "service_account",
            "project_id" => config('services.firebase.project_id'),
            "private_key_id" => config('services.firebase.private_key_id'),
            "private_key" => config('services.firebase.private_key'),
            "client_email" => config('services.firebase.client_email'),
            "client_id" => config('services.firebase.client_id'),
            "auth_uri" => "https://accounts.google.com/o/oauth2/auth",
            "token_uri" => "https://oauth2.googleapis.com/token",
            "auth_provider_x509_cert_url" => "https://www.googleapis.com/oauth2/v1/certs",
            "client_x509_cert_url" => config('services.firebase.client_x509_cert_url')
        ]);

        $this->firebase = (new Factory)
            ->withServiceAccount($serviceAccount)
            ->withDatabaseUri(config('services.firebase.database_url'))
            ->create();
    }

    /**
     * Verify password agains firebase
     * @param $email
     * @param $password
     * @return bool|string
     */
    public function verifyPassword($email, $password)
    {
        try {
            $response = $this->firebase->getAuth()->verifyPassword($email, $password);
            return $response->uid;
        } catch (FirebaseEmailExists $e) {
            logger()->info('Error login to firebase: Tried to create an already existent user');
        } catch (Exception $e) {
            logger()->error('Error login to firebase: ' . $e->getMessage());
        }
        return false;
    }
}

您的特定问题的直接解决方案不是调用 ServiceAccount::fromArray() - 您可能遵循了针对 4.x 版本的教程 article/video。 Please also see the related section in the troubleshooting section of the documentation.

更好的解决方案是使用为您设置 SDK 的 kreait/laravel-firebase 包。