如何为Web应用程序创建FCM令牌?

时间:2017-04-24 06:23:06

标签: javascript java firebase google-cloud-messaging firebase-cloud-messaging

我想基于此创建用于Web应用程序的FCM令牌我想发送推送通知。这可能吗?我可以期待这样的示例代码吗?

我试试这个

  var config = {
    apiKey: "AIzaSyC2GoeeoYfPTgP61w77FMPFep-cLBz9Pmc",
    authDomain: "sample-3a7a1.firebaseapp.com",
    databaseURL: "https://sample-3a7a1.firebaseio.com",
    projectId: "sample-3a7a1",
    storageBucket: "sample-3a7a1.appspot.com",
    messagingSenderId: "990467369229"
  };
  firebase.initializeApp(config);
const messaging=firebase.messaging();
messaging.requestPermission()
.then(function(){
console.log('Have permission');
return messaging.getToken();
})
.then(function(token){
console.log(token);
})

但显示以下错误

Uncaught e {code: "app/no-app", message: "Firebase: No Firebase App '[DEFAULT]' has been cre…- call Firebase App.initializeApp() (app/no-app).", name: "[DEFAULT]", stack: "FirebaseError: Firebase: No Firebase App '[DEFAULT…    at http://localhost:8080/FCMPushNotify/:88:30"}

0 个答案:

没有答案