2017-09-05 6 views
1

NodeJS Client Web AppFCMから設定しようとしています。私はサーバー側に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 
+0

火災基地が搭載されているかどうかを確認します。 –

+0

はい、そうです。私は 'console.log(firebase);でオブジェクトを取得しています。しかし、 'messaging()'関数はありません。私は質問にそれを追加します。 – ashwinx

答えて

0

あなたはdocumentationからの基本的な統合の手順に従わなかったように見えます。

<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-messaging.js"></script> 

また、4.2.0のWebクライアントの最新バージョンにも注意してください。あなたは古いバージョンです。

+0

私が投稿したhtmlファイルは、ドキュメントからのものです。私が言ったように、おそらくバージョンの競合です、私はこれを試して戻ってくるでしょう。ありがとう。 – ashwinx

+0

どのようなドキュメントを参照していますか?私が示したものは標準的です。公式のFirebaseのドキュメントでは古いバージョンのものは表示されません。 –

+0

また、「firebase-messaging.js」は「firebase.js」だけでなく「firebase-messaging.js」も含めています。 –

関連する問題