gpt4 book ai didi

javascript - 网络上的 Google Cloud Messaging,无法获取 token

转载 作者:行者123 更新时间:2023-12-03 04:54:08 24 4
gpt4 key购买 nike

我需要一些有关 Firebase 云消息传递的帮助,因为我真的不知道为什么我无法获取 token 。

我尝试下载示例项目,清除所有不必要的内容并按照此视频 Getting Started with Firebase Cloud Messaging on the Web - 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>

但是我从来没有得到 token ,当我在控制台中调试它时,messaging.getToken() 确实返回了 Promise,但处于挂起状态,没有任何值:

messaging.getToken()
Promise__proto__: Promise[[PromiseStatus]]: "pending"[[PromiseValue]]: undefined

有人可以帮我解决这个问题吗?

最佳答案

经过 4 个小时的尝试,我发现“authDomain”必须是 HTTPS 服务器 url

关于javascript - 网络上的 Google Cloud Messaging,无法获取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com