Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Error: Credentials fetcher does not implement Google\Auth\UpdateMetadataInterface

Please I'm trying to fetch data from firebase in PHP, and it's giving me this error

Uncaught RuntimeException: Credentials fetcher does not implement Google\Auth\UpdateMetadataInterface

this is my code:

require_once 'vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;

$db = new FirestoreClient([
    'projectId' => 'firebase-db-name'
]);


$docRef = $db->collection('collection')->document('document');
$snapshot = $docRef->snapshot();

if ($snapshot->exists()) {
printf('Document data:' . PHP_EOL);
print_r($snapshot->data());
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}

please what i'm i doing wrong or what do i suppose to import into the code for it to work and stop giving me the error

like image 839
Paulos Ab Avatar asked Mar 02 '23 21:03

Paulos Ab


2 Answers

I worked for me

'project_Id' => 'firebase-db-name',

'keyFile' => json_decode(file_get_contents('./file.json'), true)

get KeyFile = Firebase Console/Project Settings/Service accounts/Firebase admin SDK/-> Generate new private key then download it and past it with file.json

percent: 100% sussced

like image 58
Thắng Trương Khắc Avatar answered Mar 05 '23 17:03

Thắng Trương Khắc


I was having the same issue in a Laravel 7 project. I found a solution by activating Firestore API. Maybe this solution will help you.

like image 32
Muddassir Izhar Avatar answered Mar 05 '23 18:03

Muddassir Izhar