2

In recent days, i have encountered a few problems with my old firebase sdk's in both android and server node js 'firebase' sdk. Sending notifications and retrieving data. After i updated android dependencies with newest version, notification problem was solved. But in server side:

Problem with the following example:

var admin = require("firebase-admin");
var serviceAccount = require("filepath.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://dbname.firebaseio.com"
});

var db = admin.database();
var ref = db.ref("myval");

ref.once("value",function(snapshot){
    console.log(snapshot.val());
});

Example does not return any value or error, just waiting. Sure there is 'myval' child under main database tree.

What wrong may cause the problem?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
mayhan
  • 51
  • 5

1 Answers1

3

Solved the problem with help of firebase team.

Enabling the logging before database definition with:

admin.database.enableLogging(true);
var db = admin.database();

helps for debugging. After that I got the error:

Failed to get token: Error: Error fetching access token: invalid_grant (Invalid JWT: Token must be a short-lived token and in a reasonable timeframe)

And according to this: Authentication on google: OAuth2 keeps returning 'invalid_grant' my machine timezone was not syncronized appropriately with a ntp server, which is required for new admin authentication in my case.

Then (in ubuntu 14.04) setting the timezone (timezones are here: '$ timedatectl list-timezones') :

$ sudo timedatectl set-timezone desired_timezone

solved the problem!

Thanks for helps.

Community
  • 1
  • 1
mayhan
  • 51
  • 5