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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With