[英]How do you get client-side firebase cloud messaging token into google cloud function?
[英]Google Cloud Messaging on web, cant get token
我需要有關Firebase雲消息傳遞的幫助,因為我真的不知道為什么無法獲得令牌。
我嘗試下載示例項目,清除所有不必要的內容,然后按照此視頻中的說明實施它,如Web上Firebase Cloud Messaging入門-Firecasts
我的示例代碼如下所示:
<!DOCTYPE html> <html> <head> <meta charset=utf-8/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Firebase Cloud Messaging Example</title> <link rel="stylesheet" href="main.css"> <link rel="manifest" href="/manifest.json"> </head> <body> <script src="https://www.gstatic.com/firebasejs/3.6.10/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: "MYAPPKEY", authDomain: "PROJECT_NAME.firebaseapp.com", databaseURL: "https://PROJECT_NAME.firebaseio.com", storageBucket: "PROJECT_NAME.appspot.com", messagingSenderId: "SENDER_ID" }; firebase.initializeApp(config); const messaging = firebase.messaging(); messaging.requestPermission() .then(function() { console.log("Have perm"); return messaging.getToken(); }).then(function(token) { //never get here console.log(token); }).catch(function(err) { console.log("Err: ", err); }); </script> </body> </html>
但是我從來沒有得到令牌,當我在控制台中調試它時,messaging.getToken()確實返回Promise,但是沒有任何價值:
messaging.getToken()
Promise__proto__: Promise[[PromiseStatus]]: "pending"[[PromiseValue]]: undefined
誰能幫我這個?
經過4個小時的嘗試,我重新整理后,該“ authDomain”必須為HTTPS服務器網址
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.