Firestore:代码16(请求具有无效的身份验证凭据) [英] Firestore: code 16 (Request had invalid authentication credentials)

查看:58
本文介绍了Firestore:代码16(请求具有无效的身份验证凭据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过私钥和管理员权限以管理员权限访问Firestore,以便我可以将其用于后端的查询和内容.

i am trying to access Firestore with admin permissions via private key and admin permissions so i can use it for queries and stuff in the backend.

//i import fb-admin
const firebaseAdmin = require('firebase-admin')

//i initialize as admin with a valid credential
firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert('./pathto/myprivatekeyinfo.json')
})

//i initialize firestore
var dba = firebaseAdmin.firestore()

//i test the connection by listing all the available collections
dba.getCollections().then(collectionList => {
  collectionList.forEach(collection => {
    console.log(collection.id) //print available collections
  }
},error => console.error(JSON.stringify(error,null,"  "))) //print error

这似乎与文档中的说明完全一样,但是我的问题是,在尝试执行Node的某些计算机上,我只能设法随机连接几台计算机.

It seems exactly like instructed in the documentation, but my problem is that with some computers that i try to execute Node in, i only manage to connect at random on a few.

有时我会连接并且运行良好,并按应有的方式打印可用的集合,但是大多数时候,我得到的都是由于无效凭据导致的错误

Sometimes i connect and it goes fine, printing the available collections as it should, but most of the time all i get is this error for invalid credentials

{
  "code": 16,
  "metadata": {
    "_internal_repr": {
      "www-authenticate": [
        "Bearer realm=\"https://accounts.google.com/\""
      ]
    }
  },
  "details": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
  "note": "Exception occurred in retry method that was not classified as transient"
}

我尝试不进行任何更改,并且有时在某些我测试完全相同的代码的计算机上也可以使用,但是在其他计算机上却不能,并且尝试通过firebase控制台获取新的私钥对此没有任何改变.当我尝试连接时,有时会花费很长时间才出现此错误,否则它根本不会回叫.提供的链接也无济于事,因为它只提供了一些JS代码,供通过前端进行常规访问以登录google,这在这种情况下根本不是我的用例(我已经尝试过配置项目"按钮).

i've tried changing nothing and it works sometimes on some computers where i test the exact same code, but in others it doesn't, and trying to get a new private key via the firebase console changes nothing in the matter. When i try to connect it sometimes takes too long just to get this error or it does not call back at all. The link provided isn't helpful either, as it only gives some JS code for regular access via the front end to login with google which isn't my use case at all in this situation (i've tried the "configure a project" button too).

我在这里做错什么吗?为什么有时什么也没做,有时却什么都不做,为什么有时能起作用?

is there anything that i am doing really wrong here? why does it work sometimes although changing nothing and sometimes it just doesn't?

我感谢您的帮助

推荐答案

此错误与该错误基本相同(

This error is basically the same to this one (Not able to send device push notification due to app/invalid-credential error), where the clock of the computer needs to be synced to the clock of the firebase server.

在一个朋友试图指出这一点之前,我一直无法在各种计算机上测试它(所有时钟设置错误)而无法连接,所以我进行了测试并成功了.

i was stuck trying to test it in various computers (all with the wrong set up clock) without being able to connect before a friend tried to point out that, so i tested and it worked.

对我有用的解决方案肯定是检查计算机上时钟的设置.

The solution that worked for me was definitely to check the set up clock on the computer.

这篇关于Firestore:代码16(请求具有无效的身份验证凭据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆