我安装了与其关联的所有软件包,其中包括 https://cloud.google.com/php/grpc#windows。
我正在使用 XAMPP 运行它
代码如下:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Kreait\Laravel\Firebase\Facades\Firebase;
use Google\Cloud\Firestore\FirestoreClient;
class FirebaseController extends Controller
{
public function test()
{
$database = app('firebase.firestore')->database();
$database1 = app('firebase.firestore')->database()->collection('test');
$database2 = app('firebase.firestore')->database()->collection('test')->document(1);
//this prints
echo '<pre>';
print_r($database);
print_r($database1);
print_r($database2);
//this causes the error and any other attempts to perform CRUD
$documents = app('firebase.firestore')->database()->collection('test')->documents();
}
}
现行规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
我也尝试允许所有,以防万一这是原因,但我仍然遇到相同的错误
上面 print_r 按顺序输出
Google\Cloud\Firestore\FirestoreClient Object
(
[connection:Google\Cloud\Firestore\FirestoreClient:private] => Google\Cloud\Firestore\Connection\Grpc Object
(
[serializer] => Google\ApiCore\Serializer
[firestore] => Google\Cloud\Firestore\V1\FirestoreClient
[resourcePrefixHeader] => projects/myproject/databases/(default)
[databaseRoutingHeader] => project_id=myproject&database_id=(default)
[isUsingEmulator] =>
)
[database:Google\Cloud\Firestore\FirestoreClient:private] => (default)
[valueMapper:Google\Cloud\Firestore\FirestoreClient:private] => Google\Cloud\Firestore\ValueMapper Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[returnInt64AsObject] =>
)
[projectId:Google\Cloud\Firestore\FirestoreClient:private] => myproject
)
Google\Cloud\Firestore\CollectionReference Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[valueMapper] => Google\Cloud\Firestore\ValueMapper Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[returnInt64AsObject] =>
)
[name] => projects/myproject/databases/(default)/documents/test
[parent] =>
)
Google\Cloud\Firestore\DocumentReference Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[valueMapper] => Google\Cloud\Firestore\ValueMapper Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[returnInt64AsObject] =>
)
[parent] => Google\Cloud\Firestore\CollectionReference Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[valueMapper] => Google\Cloud\Firestore\ValueMapper Object
(
[connection] => Google\Cloud\Firestore\Connection\Grpc
[returnInt64AsObject] =>
)
[name] => projects/myproject/databases/(default)/documents/test
[parent] =>
)
[name] => projects/myproject/databases/(default)/documents/test/1
)
同样的问题“ERR_CONNECTION_RESET” 我认为是直接来自 Firebase 或 PHP 包的错误。
我可以使用 Admin SDK 进行身份验证,但是当我使用 Firebase 时则不起作用。