【问题标题】:Firebase Error: Credentials fetcher does not implement Google\Auth\UpdateMetadataInterfaceFirebase 错误:凭据提取器未实现 Google\Auth\UpdateMetadataInterface
【发布时间】:2021-03-05 08:48:58
【问题描述】:

请我尝试从 PHP 中的 firebase 获取数据,它给了我这个错误

Uncaught RuntimeException: Credentials fetcher does not implement Google\Auth\UpdateMetadataInterface

这是我的代码:

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());
}

请问我做错了什么或者我想将什么导入到代码中以使其工作并停止给我错误

【问题讨论】:

    标签: php firebase google-cloud-platform google-cloud-firestore


    【解决方案1】:

    我为我工作

    '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/-> 生成新的私钥 然后下载它并用 file.json 过去

    百分比:100% 搁置

    【讨论】:

      【解决方案2】:

      我在 Laravel 7 项目中遇到了同样的问题。我通过激活 Firestore API 找到了解决方案。也许这个解决方案会对你有所帮助。

      【讨论】:

      • 我启用了它。并且还在代码中添加 JSON 服务帐户文件,但仍然面临此错误。 “凭据提取器未实现 Google\Auth\UpdateMetadataInterface”
      猜你喜欢
      • 2019-12-17
      • 2017-10-13
      • 2018-04-14
      • 2021-10-14
      • 2017-09-23
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多