[英]Firebase messaging missing Authentication key in MongoDB trigger functions:
Please I need help.我需要帮助。 I don't know what I am doing wrong.
我不知道我做错了什么。 I am trying to send push notification from http request but I keep getting this error:
我正在尝试从 http 请求发送推送通知,但我不断收到此错误:
The request was missing an Authentication Key.
该请求缺少身份验证密钥。 Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server .
请参阅 FCM 文档的“身份验证”部分,地址为https://firebase.google.com/docs/cloud-messaging/server 。
I am currently doing this:我目前正在这样做:
const response = await context.http.post({
url:"https://fcm.googleapis.com/fcm/send",
header:{"Content-Type": "application/json",
"Authorization":"key= Web Server Key"},
body:{
"to": usersPushToken, // From FirebaseMessaging.instance.getToken();
"notification": {
"title": "Title",
"body": "body",
"clickAction": 'FLUTTER_NOTIFICATION_CLICK',
"sound": 'default',
},
}
},
encodeBodyAsJSON: true,
});
My web server key (Cloud Messaging API (Legacy)) I also tried API key:我的 web 服务器密钥(Cloud Messaging API (Legacy))我也试过 API 密钥:
This was my fault (headers not header)
.这是我的错
(headers not header)
。 But I will leave this answer for anyone using Flutter , MongoDB , and Firebase Messaging .但我会为使用Flutter 、 MongoDB和Firebase Messaging的任何人留下这个答案。
const response = await context.http.post({
url:"https://fcm.googleapis.com/fcm/send",
"headers":{"Content-Type": ["application/json"], //Must be in array
"Authorization":["key= Web Server Key"]}, //Must be in array
"body":{
"to": usersPushToken, // From FirebaseMessaging.instance.getToken();
"notification": {
"title": "Title",
"body": "body",
"clickAction": 'FLUTTER_NOTIFICATION_CLICK',
"sound": 'default',
},
}
},
encodeBodyAsJSON: true,
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.