2017-02-24 184 views
1
var admin = require("firebase-admin"); 
var serviceAccount = require("service_account.json") 

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

返回:火力地堡AdminSDK initializeApp返回INVALID_TOKEN

Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: invalid_grant (Invalid JWT: Token must be a short-lived token and in a reasonable timeframe)". The most likely cause of this error is using a certificate key file which has been revoked. Make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-admin/serviceaccounts/project . If not, generate a new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk .

的service_account和密鑰ID是否存在。

+0

服務器時間未同步。此線程有助於解決,http://stackoverflow.com/questions/41712965/how-to-connect-to-firebase-by-firebase-admin-against-a-proxy – user3288414

+1

我會確保添加此案例到即將發佈的版本的錯誤消息,以便將來的開發人員不會遇到此問題。感謝您報告!我很高興你把這一切都弄清楚了。 – jwngr

回答

0

同樣的事件發生在我身上。我有一個結構,管理員是nodejs,客戶端是android和ios。這發生在我身上,當我試圖在我的本地主機中運行,然後我將管理員移至heroku並解決。

+1

服務器時間未同步。你可能遇到了這個問題。此線程有助於解決,http://stackoverflow.com/questions/41712965/how-to-connect-to-firebase-by-firebase-admin-against-a-proxy – user3288414