【问题标题】:Firebase 3 - Can't retrieve data from database (Web)Firebase 3 - 无法从数据库(Web)中检索数据
【发布时间】:2016-10-15 11:34:11
【问题描述】:

我第一次使用Firebase 3(最新版本)开发一个网络应用程序,但我在我的页面上遇到了retrieving data 的问题。

我从Heroku 创建了一个NodeJS 测试应用程序,然后我尝试以JSON 格式检索我的数据(参考路径转到我的数据数组)保存在我的Firebase realtime database 中。 我关注了doc,但没有结果。

这是我的代码:

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>

// Initialize Firebase
var config = {
    apiKey: "*******",
    authDomain: "*******",
    databaseURL: "*******",
    storageBucket: "*******",
};

firebase.initializeApp(config);
firebase.database().ref('my/path/to/data').on('value', function(snapshot) {
    console.log('kk'); //no log in the console
});

</script>

控制台中没有错误,但也没有结果。看起来很简单,但我不知道我错过了什么。

【问题讨论】:

    标签: javascript node.js heroku firebase firebase-realtime-database


    【解决方案1】:

    这一直在我的应用程序中工作:

    firebase.database()
      .ref(`/database/path`)
      .once('value')
      .then((snapshot) => { console.log('hi') });
    

    【讨论】:

    • 我在控制台中收到此错误:firebase.js:442 Uncaught (in promise) 错误:permission_denied at /my/path/to/data:客户端无权访问所需数据
    • 检查数据库访问权限,如下所述:firebase.google.com/docs/database/security
    【解决方案2】:

    这很奇怪,但下面的代码有效。

    var user = firebase.auth().currentUser;
    
    firebase.database().ref('users/' + user.uid + '/<your-object-name>').once('value', function(snapshot) {
        console.log('A----->');
        console.log('snapshot', JSON.stringify(snapshot.val()));
    });
    

    用你的对象替换&lt;your-object-name&gt;

    【讨论】:

      猜你喜欢
      • 2018-07-09
      • 1970-01-01
      • 2018-09-04
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多