Javascript 使用node.js web服务器写入Firebase数据库-“;FIREBASE警告:设置为。。。失败:权限“被拒绝”;
我有一个node.js web服务器,我正试图通过它写入Firebase。但是,无论何时运行,我都会收到以下错误消息:Javascript 使用node.js web服务器写入Firebase数据库-“;FIREBASE警告:设置为。。。失败:权限“被拒绝”;,javascript,node.js,firebase,webserver,Javascript,Node.js,Firebase,Webserver,我有一个node.js web服务器,我正试图通过它写入Firebase。但是,无论何时运行,我都会收到以下错误消息: FIREBASE WARNING: set at /mydb failed: permission_denied 以下是我如何设置我的应用程序(相关详细信息): 调用函数: //what details looks like: //{ title: 'Details', //description: 'Really fast, and awesome.', //ta
FIREBASE WARNING: set at /mydb failed: permission_denied
以下是我如何设置我的应用程序(相关详细信息):
调用函数:
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
为了让Firebase接受我的帖子,我需要做什么?我已经阅读了一些关于这方面的文件:
您完成firebase sdk设置了吗? 您需要下载一个JSON文件,并将其放入节点服务器。 然后使用此代码初始化firebase
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
apiKey: "8oc57xxx",
authDomain: "example-04.firebaseapp.com",
databaseURL: "https://example-ex04.firebaseio.com",
projectId: "example-ex04",
storageBucket: "example-ex04.appspot.com",
messagingSenderId: "5022"
});
function writeData(details) {
admin.database().ref('mydb/').push({
title: details.title,
description: details.description,
tags: details.tags
}).then(function() {
console.log('Upload succeeded');
}).catch(function(error) {
console.log('Upload failed');
});;
}
调用函数:
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
你可以在这个谷歌网站上查询
您完成firebase sdk设置了吗? 您需要下载一个JSON文件,并将其放入节点服务器。 然后使用此代码初始化firebase
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
apiKey: "8oc57xxx",
authDomain: "example-04.firebaseapp.com",
databaseURL: "https://example-ex04.firebaseio.com",
projectId: "example-ex04",
storageBucket: "example-ex04.appspot.com",
messagingSenderId: "5022"
});
function writeData(details) {
admin.database().ref('mydb/').push({
title: details.title,
description: details.description,
tags: details.tags
}).then(function() {
console.log('Upload succeeded');
}).catch(function(error) {
console.log('Upload failed');
});;
}
调用函数:
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
//what details looks like:
//{ title: 'Details',
//description: 'Really fast, and awesome.',
//tags: 'tag-1'
//}
exports.postDetails = (req, res, next) => {
writeData(req.body);
const errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/example');
}
req.flash('success', { msg: 'Success!' });
res.redirect('/example');
};
你可以在这个谷歌网站上查询