使用新的Firebase的Nodejs应用程序不会检索数据库项目 [英] Nodejs app with new Firebase does not retrieve database items

查看:335
本文介绍了使用新的Firebase的Nodejs应用程序不会检索数据库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的nodejs,但已经有一个工作的js客户端程序,在Firebase版本3.0.2。事实证明,我需要一个服务器来做一些简单的事情,在js客户端中是不可能的。

当我在nodejs中尝试这个基本的东西时,没有任何反应 - 数据库从不被检索,并且节点服务器程序继续运行而没有错误。服务器程序(server.js)如下:

  var firebase = require(firebase); 

var myApp = firebase.initializeApp({
serviceAccount:xxx / xxx.json,
databaseURL:https://xxx.firebaseio.com
}); $()


firebase.database()。ref()。从来没有拿过
console.log(snapshot.val());
});

数据库加载了数据,并且正在试图查看根目录。当我通过控制台添加项目到数据库,仍然没有任何反应。更具体的ref()值不起作用。

我正在使用节点版本v4.4.4。这个程序是在命令行(在MBP / OSX上)用node server.js调用的。

我花了好几个小时来弄清楚我在做什么错 - 可能是一些愚蠢的!感谢您的帮助。

解决方案

修正!


  1. 增加了调试,这是必不可少的:

    firebase.database.enableLogging(true)

    p:0:from server:{r:2,b:{s:invalid_token,d :拒绝访问。}}



    (注意:没有日志记录,这完全是无声的!

  2. 事实证明,这个服务帐户是不正确的!你必须先确定服务条款!为此,请转到 https://console.cloud.google.com/


  3. 重新创建了一个新的服务帐户,并将其挂钩 - 最后,它可以正常工作!


I am new to nodejs, but have already a working js client program, in Firebase Version 3.0.2. It turns out I need a server for doing some simple things not possible in a js client.

When I try this basic thing in nodejs, nothing happens - the data in the database is never retrieved, and the node server program continues to run with no errors. The server program (server.js) is as follows:

var firebase = require("firebase");

var myApp =firebase.initializeApp({
    serviceAccount: "xxx/xxx.json",
    databaseURL:  "https://xxx.firebaseio.com"
});


firebase.database().ref().on('value', function(snapshot) {
    console.log("urls value changed");   // NEVER GETS HERE
    console.log(snapshot.val());
});

The database is loaded with data, and this is trying to look at the root. When I add items to the database via the console, still nothing happens. More specific ref() values has no effect.

I'm using node version v4.4.4. The program is invoked at the command line (on a MBP/OSX) with "node server.js".

I have spent hours trying to figure out what I am doing wrong - probably something stupid! Thanks for help in advance.

解决方案

Fixed!

  1. Added debugging, which is essential:

    firebase.database.enableLogging(true)

  2. Saw that there was an invalid token, and was continually being disconnected/reconnected to try again. Lines in the log like:

    p:0: from server: {"r":2,"b":{"s":"invalid_token","d":"Access denied."}}

    (NOTE: without the logging, this was totally silent!).

  3. It turns out the service account was not correctly made! You must ok terms of service first! To do this: go to https://console.cloud.google.com/

  4. Recreated a new service account and hooked it up - and finally, it works!

这篇关于使用新的Firebase的Nodejs应用程序不会检索数据库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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