0

Does this error have anything to do with the Firebase version? If not, how do I solve this issue?

private static function fromJsonFile(string $filePath): self
{
    try {
        $file = new \SplFileObject($filePath);
        $json = (string) $file->fread($file->getSize());
    } catch (Throwable $e) {
        throw new InvalidArgumentException("{$filePath} can not be read: {$e->getMessage()}");
    }

    try {
        $serviceAccount = self::fromJson($json);
    } catch (Throwable $e) {
        throw new InvalidArgumentException(\sprintf('%s could not be parsed to a Service Account: %s', $filePath, $e->getMessage()));
    }

    return $serviceAccount;
}
Willie Chalmers III
  • 1,151
  • 1
  • 16
  • 29

1 Answers1

1

The code you posted is from kreait/firebase-php and shows a private method from the ServiceAccount class that can not be called directly since release 5.0 of the SDK.

Straight from the troubleshooting section in the documentation:

You probably followed a tutorial article or video targeted at a 4.x version, and your code looks like this:

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

Change it to the following:

use Kreait\Firebase\Factory;

$factory = (new Factory)->withServiceAccount(__DIR__.'/google-service-account.json');

$database = $factory->createDatabase();
jeromegamez
  • 3,348
  • 1
  • 23
  • 36
  • Yes,the error had something to do with the version. Unfortunately,changing code came with some complications. – kakembo samuel Nov 06 '20 at 18:51
  • I was able to fix them by lowering the firebase version to 4.18. 5.0 made everything hard.By following this link https://stackoverflow.com/questions/39136746/firebase-connection-with-codeigniter-in-php it was almost effortless! Thanks for your help! – kakembo samuel Nov 06 '20 at 18:56