NodeJS Client Web App
をFCM
から設定しようとしています。私はサーバー側にfirebase-admin
を設定しました。トークンにアクセスするようにクライアントを設定しているうちに、TypeError: firebase.messaging is not a function
エラーが発生しています。他のソリューションからは、さまざまなFCMバージョン間の互換性エラーのように思えますが、それでも修正できます。以下は私が使用しているhtmlファイルですFirebase:firebase.messaging()は関数ではありません
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>
</head>
<body>
<script>
console.log(firebase);
const messaging = firebase.messaging();
messaging.onTokenRefresh(function() {
messaging.getToken()
.then(function (refreshedToken) {
console.log('Token refreshed.');
console.log(refreshedToken);
// // Indicate that the new Instance ID token has not yet been sent to the
// // app server.
// setTokenSentToServer(false);
// // Send Instance ID token to app server.
// sendTokenToServer(refreshedToken);
// // [START_EXCLUDE]
// // Display new Instance ID token and clear UI of all previous messages.
// resetUI();
// // [END_EXCLUDE]
})
.catch(function (err) {
console.log('Unable to retrieve refreshed token ', err);
// showToken('Unable to retrieve refreshed token ', err);
});
});
</script>
</body>
</html>
ファイアベースをクライアント側で正しく設定する方法はありますか? EDIT:console.log(firebase)
が得られます。
SDK_VERSION: "3.1.0", initializeApp: ƒ, app: ƒ, Promise: ƒ, …}
INTERNAL:{registerService: ƒ, createFirebaseNamespace: ƒ, extendNamespace: ƒ, createSubscribe: ƒ, ErrorFactory: ƒ, …}
Promise:ƒ Promise()
SDK_VERSION : "3.1.0"
User:ƒ (a,b,c)
app:ƒ a(a)
apps:(...)
auth:ƒ (c)
database:ƒ (c)
initializeApp:ƒ (a,c)
storage:ƒ (c)
get apps:ƒ()
__proto__
:
Object
火災基地が搭載されているかどうかを確認します。 –
はい、そうです。私は 'console.log(firebase);でオブジェクトを取得しています。しかし、 'messaging()'関数はありません。私は質問にそれを追加します。 – ashwinx