I'm a new one to this Firestore PHP library. So I tried to install the Google Library via Composer with command :
$ composer require google/cloud-firestore
and
$ composer require google/cloud
and
$ composer require google/cloud-storage
Then I installed gRPC on my XAMPP, and follow the instruction on this link : Google Cloud PHP Authentication. After that, I follow a sample on this instruction : Google Cloud PHP Sample
But it returns an error like this
Fatal error: Uncaught Error: Call to undefined method Google\Cloud\Storage\StorageClient::collection() in C:\xampp\htdocs\phpfirebasecomposer\firestore.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\phpfirebasecomposer\firestore.php on line 3
This is my dbcon.php, which I used to store the credential and authentication attempts
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\Auth;
use Google\Cloud\Firestore\FirestoreClient;
use Google\Cloud\Storage\StorageClient;
// Authenticating with keyfile data.
$firestore = new FirestoreClient([
'projectId' => 'myid',
]);
// Authenticating with a keyfile path.
$firestore = new StorageClient([
'keyFilePath' => 'my.json'
]);
$firestore = new StorageClient([
'keyFile' => json_decode(file_get_contents('my.json'), true)
]);
$factory = (new Factory)
->withServiceAccount('my.json')
->withDatabaseUri('dblink');
$database = $factory->createDatabase();
$auth = $factory->createAuth();
?>
And this is the firestore.php that I used to echo the desired data
<?php
include 'dbcon.php';
$collectionReference = $firestore->collection('users');
$documentReference = $collectionReference->document('a4Wq47gPeqY3UjeGbR40ptPZ0sq2');
$snapshot = $documentReference->snapshot();
echo "Hello " . $snapshot['uid'];
?>
What I'm asking is, what could possibly be the problem of undefined method ? Thanks