Reputation: 3652
I'm unable to connect to firestore after following the install guide, what am I missing to get this working?:
Guide:
Code:
<?php
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;
$firestore = new FirestoreClient([
'keyFilePath' => '/var/www/path/to/my/key.json',
'projectId' => 'test-app',
]);
Composer json:
{
"require": {
"grpc/grpc": "^1.38",
"google/cloud-firestore": "^0.1.0",
"google/apiclient": "^2.12.1",
"google/cloud-core": "^1.47"
}
}
Error:
==> /var/log/apache2/error.log <== [Tue Oct 04 02:47:33.613513 2022] [php7:error] [pid 2826323] [client my.IP.address] PHP Fatal error: Uncaught Error: Class 'Google\ApiCore\Serializer' not found in /var/www/html/vendor/google/cloud-core/src/GrpcRequestWrapper.php:93\nStack trace:\n#0 /var/www/html/vendor/google/cloud-firestore/Connection/Grpc.php(81): Google\Cloud\Core\GrpcRequestWrapper->__construct()\n#1 /var/www/html/vendor/google/cloud-firestore/FirestoreClient.php(111): Google\Cloud\Firestore\Connection\Grpc->__construct()\n#2 /var/www/html/v.php(8): Google\Cloud\Firestore\FirestoreClient->__construct()\n#3 {main}\n thrown in /var/www/html/vendor/google/cloud-core/src/GrpcRequestWrapper.php on line 93
Upvotes: 1
Views: 2541
Reputation: 51
TL;DR composer require "google/cloud-firestore" "^1.37.0"
For some reason when you require "google/cloud-firestore" composer instals very old "^0.1.0" version by default.
That "^0.1.0" version in turn depends on "google/gax": "^0.25" that has Google\GAX
namespace for classes like Serializer
. The core of the error is here.
You should exec command: composer require "google/cloud-firestore" "^1.37.0"
to install proper "google/gax": "^1.19.1" that has Google\ApiCore\Serializer
class.
Upvotes: 3
Reputation: 3652
Turns out this was a composer issue. I needed to remove "google/cloud-firestore": "^0.1.0",
and just keep "google/cloud-core": "^1.47"
Updated the file and then ran: composer require google/cloud -W
Composer json:
{
"require": {
"grpc/grpc": "^1.38",
"google/apiclient": "^2.12.1",
"google/cloud-core": "^1.47"
}
}
Upvotes: 1