我在php中使用firebase作为后端,但是当我将"fromJsonFile“方法称为"ServiceAccount"时,会出现以下错误:
致命错误:未知错误:从上下文“”调用私有方法Kreait\Firebase\ServiceAccount::fromJsonFile()在C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php:7堆栈跟踪中:#0 C:\xampp\htdocs\wordpress\wp-content\plugins\sb-api\sb_api.php(31):include() #1 C:\xampp\htdocs\wordpress\wp-settings.php(362):C:\xampp\htdocs\wordpress\wp-admin\admin.php(34):include_once(‘C:\xampp\htdocs.’) #2 C:\xampp\htdocs\wordpress\wp-config.php(90):require_once(‘C:\xampp\htdocs.’)#3C:\xampp\htdocs\wordpress\wp-load.php(37):require_once(‘C:\xampp\htdocs.’) #4(‘C:\xampp\htdocs.’) #5 C:\xampp\htdocs\wordpress\wp-admin\index.php(10):require_once(‘C:\xampp\htdocs.’) #6 {main}抛入第7行的C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php中
The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.这里是我的代码:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
$database = $firebase->getDatabase();
?>发布于 2020-04-12 16:38:23
您能告诉我们当前使用的firebase-php的版本吗?
如果您使用的版本低于5.x,请更新到最新版本。
https://github.com/kreait/firebase-php它使用的是php 7.2^。当前wordpress需要7.3,因此必须更新为最新版本
这也是文档。
https://firebase-php.readthedocs.io/en/latest/我不知道具体问题是什么,但似乎错误说您不能访问私有方法,所以您应该通过将它更新为公共或公共静态方法来访问它。
发布于 2020-05-14 09:35:50
对于ver5.x
// @see https://firebase-php.readthedocs.io/en/5.2.0/troubleshooting.html
$factory = (new Factory)->withServiceAccount(__DIR__.'/google-service-account.json');
$database = $factory->createDatabase();
// if you want auth
//$auth = $factory->createAuth();https://stackoverflow.com/questions/61166472
复制相似问题