我在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;
}
}
答案 0 :(得分:0)
针对您的特定问题的直接解决方案是不致电ServiceAccount::fromArray()
-您可能遵循了针对4.x版本的教程文章/视频。 Please also see the related section in the troubleshooting section of the documentation.
更好的解决方案是使用kreait/laravel-firebase
软件包为您设置SDK。