我正在尝试将防火墙推送通知集成到我的react应用程序中。
我遵循了下面的教程
https://dzone.com/articles/how-to-add-push-notifications-on-firebase-cloud-me
https://github.com/pavelpashkovsky/react-fcm
直到Token receiving,一切都很好。然后,我尝试使用curl脚本发送通知,如下所示
curl -X POST -H "Authorization: key=AAAAAJjqjp4:APA91bFeAaBEuHXFbcDPBgFs4p......END2341BK8HLL0uMum4" -H "Content-Type: application/json" \
-d '{
"data": {
"notification": {
"title": "FCM Message",
"body": "This is an FCM Message",
"icon": "/itwonders-web-logo.png",
}
},
"to": "cG9xo6CkVNs:APA91bEd3ypeXN8P-6dbWQWf0.......NOyIytfm"
}' https://fcm.googleapis.com/fcm/send但我的反应很低
{
"multicast_id": 6820287658870793009,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "AuthenticationError"
}
]
}发布于 2020-10-30 06:18:57
在firebase-messaging-sw.js公共文件夹中创建文件,并将以下代码放入
importScripts('https://www.gstatic.com/firebasejs/7.22.0/firebase-app.js')
importScripts('https://www.gstatic.com/firebasejs/7.22.0/firebase-messaging.js')
firebase.initializeApp({
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
})
const initMessaging = firebase.messaging()在src文件夹中创建Firebase.js并像下面这样配置您的防火墙之后
import firebase from 'firebase/app';
import 'firebase/messaging';
const firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
firebase.initializeApp(firebaseConfig);
export default firebase finality将代码放在componentDidMount()中的topbar中,如下所示
import firebase from './Firebase';
componentDidMount() {
// start push notifications
const messaging = firebase.messaging()
messaging.requestPermission().then(() => {
return messaging.getToken()
}).then(token => {
console.log("Firebase Token Get::", token)
}).catch((err) => {
console.log("firebase push notification error::", err)
})
// end push notifications
}https://stackoverflow.com/questions/56735834
复制相似问题