【发布时间】:2023-03-04 13:15:01
【问题描述】:
我正在尝试设置 Firebase Cloud Messaging for Web。我设法正确初始化它并获得令牌:
<script src="https://www.gstatic.com/firebasejs/4.13.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "xxx",
authDomain: "name.firebaseapp.com",
databaseURL: "https://name.firebaseio.com",
projectId: "project-name",
storageBucket: "project-name.appspot.com",
messagingSenderId: "1111111111111"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.requestPermission().then(function() {
})
messaging.getToken().then(function(currentToken) {
console.log("token: " + currentToken);
})
</script>
+manifest.json 和 gcm_sender_id
我可以看到我正在控制台中获取令牌,因此我正在尝试验证它并通过 Postman - here is the documentation 发送我的第一个通知。
发布网址:https://fcm.googleapis.com/v1/projects/PROJECTID/messages:send 授权:无授权
标题
正文 - 令牌来自客户端函数 messaging.getToken().then(function(currentToken) {...
当我发布它时,我收到错误 401 UNAUTHENTICATED 并包含以下详细信息:
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
有什么建议可以在邮递员中正确授权并进行测试吗?谢谢
【问题讨论】:
标签: firebase oauth-2.0 firebase-cloud-messaging postman