Reputation: 3
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;
}
Upvotes: 0
Views: 2411
Reputation: 3561
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();
Upvotes: 2