【发布时间】:2016-11-07 10:27:52
【问题描述】:
我正在尝试在 node.js 中使用 Firebase,但每次重新启动服务器时都会出现以下错误:
FIREBASE 警告:提供的身份验证凭据无效。这通常表明您的 FirebaseApp 实例未正确初始化。确保您的 apiKey 和 databaseURL 与在 https://console.firebase.google.com/ 为您的应用提供的值匹配,或者如果您使用的是服务帐户,请确保它有权访问指定的 databaseURL 并且来自正确的项目。
以下是我的 index.js:_
var express = require('express');
var router = express.Router();
var mongoose=require('mongoose');
var admin=mongoose.model('admin');
var firebase = require("firebase");
// Initialize the app with no authentication
firebase.initializeApp({
serviceAccount: {
projectId: "...",
clientEmail: "...",
privateKey: "-----BEGIN PRIVATE KEY-----...",
},
databaseURL: "..."
});
console.log("sfsaf")
// The app only has access to public data as defined in the Security Rules
var db = firebase.database();
var ref = db.ref("unitalk-b9145");
var messagesRef = ref.child("messages");
messagesRef.push({
name:"Rupali",
post:"Demo test of firebase"
});
虽然我已经检查了 service-account 和 databaseURl 的路径.. 请帮忙..
【问题讨论】:
-
我收到类似的消息:FIREBASE 警告:为名为“[DEFAULT]”的应用提供的身份验证凭据无效。这通常表明您的应用程序未正确初始化。确保提供给 initializeApp() 的“credential”属性被授权访问指定的“databaseURL”并且来自正确的项目。