[英]Firebase app initialization fails with invalid-credential (firebase function initiatlization)
[英]angular-universal | firebase-admin | code: 'app/invalid-credential' |socket hang up on
import * as admin from 'firebase-admin';
var serviceAccount = require('./keys/keyfile.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://test.firebaseio.com"
});
var registrationToken = "--some-key--";
var payload = {
notification: {
title: "$GOOG up 1.43% on the day",
body: "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day."
},
data: {
stock: "GOOG",
open: "829.62",
close: "635.67"
}
};
function panelMessage(){
admin.messaging().sendToDevice(registrationToken, payload)
.then(function(response) {
// See the MessagingDevicesResponse reference documentation for
// the contents of response.
console.log("Successfully sent message:", response);
})
.catch(function(error) {
// console.log(serviceAccount);
var date = new Date();
console.log(date.toString());
console.log("Error sending message:", error);
});
}
我通過節點運行此代碼,它可以工作,但是當我以角度通用的方式添加它時
server.ts
文件..它給出以下錯誤..
發送錯誤消息:{錯誤:通過“ credential”屬性提供給initializeApp()的憑據實現無法獲取有效的Google OAuth2訪問令牌,但出現以下錯誤:“套接字掛起”。 在FirebaseAppError.FirebaseError(本機)處[本機]在新的FirebaseAppError(D:\\ angular2MH \\ firebase-panel \\ panel \\ node_modules \\ firebase-admin \\ lib \\ utils \\ error.js:39:28)中:\\ angular2MH \\ firebase-面板\\面板\\ node_modules \\ firebase-admin \\ lib \\ utils \\ error.js:84:23)位於D:\\ angular2MH \\ firebase-面板\\面板\\ node_modules \\ firebase-admin \\ lib \\ firebase-在Zone.run(D:\\ angular2MH)的ZoneDelegate.invoke(D:\\ angular2MH \\ firebase-panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js:232:26)上的app.js:119:23 \\ firebase-panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js:114:43)在D:\\ angular2MH \\ firebase-panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js在Zone.runTask(D:\\ angular2MH \\ firebase-)處的ZoneDelegate.invokeTask(D:\\ angular2MH \\ firebase-panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js:265:35):502:57 panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js:154:47)位於DrainMicroTaskQueue(D:\\ angular2MH \\ firebase-panel \\ panel \\ node_modules \\ zone.js \\ dist \\ zone-node.js: 401:35)
errorInfo:{代碼:“ app / invalid-credential”,消息:“通過“ credential”屬性提供給initializeApp()的憑據實現無法獲取有效的Google OAuth2訪問令牌,但出現以下錯誤:“套接字掛斷”。 }}
我檢查了時間(在很多地方讀過這可能是問題所在),並且它們都已同步。有人可以幫助我解決問題嗎? 我正在使用這個存儲庫
從Firebase支持中,Angular-Universal不是我們正式支持的庫。 因此無法提供OAuth。
為了解決該問題,我為Firebase制作了另一台服務器,並從通用服務器進行了api調用。 現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.