php - Fatal error: Uncaught Error: Class 'KreaitFirebaseServiceAccount' not found in
I have to learn just now write mobile app web service via fire base. I followed this link: https://firebase-php.readthedocs.io/en/stable/
In my core website i create web service folder and then create my fire.php file.This file code here,
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyC_vb5G9qs3NJsywbR34el1RaPj2HDhwNg';
$firebase = (new Factory)
->withServiceAccountAndApiKey($serviceAccount, $apiKey)
->withDatabaseUri('https://workarea-cb10b.firebaseio.com')
->create();
$database = $firebase->getDatabase();
$newPost = $database
->getReference('blog/posts')
->push([
'title' => 'Post title',
'body' => 'This should probably be longer.'
]);
$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-
$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();
I have to call my support file here: https://github.com/kreait/firebase-php/
But still I got a:
Fatal error: Uncaught Error: Class 'Kreait\Firebase\ServiceAccount' not found in /opt/lampp/htdocs/workarea/webservice/firebase/fire.php:13 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/workarea/webservice/firebase/fire.php on line 13
issue have to fix this issue. Kindly check and help me.
Mycomposer.json
file
{
"name": "kreait/firebase-php",
"description": "Firebase Admin SDK",
"keywords": ["firebase", "google", "sdk", "api", "database"],
"homepage": "https://github.com/kreait/firebase-php",
"license": "MIT",
"authors": [
{ "name": "Jérôme Gamez", "homepage": "https://github.com/jeromegamez" }
],
"require": {
"php": "^7.0",
"ext-mbstring": "*",
"ext-openssl": "*",
"fig/http-message-util": "^1.1",
"google/auth": "^0.11.0|^1.0",
"guzzlehttp/guzzle": "^6.2.1",
"kreait/firebase-tokens": "^1.1.1",
"lcobucci/jwt": "^3.2",
"mtdowling/jmespath.php": "^2.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"phpstan/phpstan-phpunit": "^0.9.2",
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": {
"Kreait\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Kreait\\Tests\\": "tests"
}
},
"config": {
"platform": {
"php": "7.0"
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
}
}
Answer
Solution:
I am sure you already got your problem solved, but for upcoming developers it might be helpful, Its issue with your composer install kreait/firebase-php using composer in cmd inside project directory and your issue will be resolved.
Answer
Solution:
I actually had the same issue and I address it by install php-psr exteion:
Created /etc/php/7.x/mods-available/psr.ini with the following lines:
and enable the extension by excuting:
and reload/restart apache, php-fpm.....
Answer
Solution:
I recommend starting from Firebase Installation. Process is described there, but the main point is this:
Install your firebase-php package in command-line with Composer:
That should fix problem with missing class.