首页 > 解决方案 > 没有从 Firestore 检索到文档

问题描述

我想从 Cloud Firestore 中检索数据,但我做不到,也不知道从哪里开始。我尝试了参考在 Firestore 中开始的代码,但未获取数据。这是我的代码

<?php

require __DIR__.'/vendor/autoload.php';

use Google\Cloud\Firestore\FirestoreClient;

$db = new FirestoreClient(
    [
        'projectId' => 'fakedata-aa798'
    ]
);

$collectionReference = $db->collection('Test3')->document('User1');

$snapshot = $collectionReference->snapshot();


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

如何从 Firestore 中获取数据?帮帮我,我不知道如何在我的环境开发中设置 GOOGLE_APPLICATION_CREDENTIALS。

标签: phpfirebasegoogle-cloud-firestore

解决方案


推荐阅读