简体   繁体   English

Firebase 消息缺少 MongoDB 触发函数中的身份验证密钥:

[英]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 密钥: 云消息传递 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 .但我会为使用FlutterMongoDBFirebase 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.

相关问题 Firebase 云消息传递 API (V1):缺少服务器密钥 - Firebase Cloud Messaging API (V1): Server Key missing 我可以在 Cloud Functions Http 触发器中创建 Firebase 身份验证用户吗? - Can I create a user on Firebase Authentication in Cloud Functions Http Trigger? 调用 firebase.messaging.getToken() 时出现“请求缺少身份验证凭据”错误 - "Request is missing authentication credential" error when calling firebase.messaging.getToken() Firebase 的云功能是否准时触发? - Cloud Functions for Firebase trigger on time? 使用 Firebase 身份验证与 mongodb 数据库 - Using Firebase Authentication with mongodb database Firebase 云消息服务器密钥显示已禁用 - Firebase cloud messaging server key showing disabled Firebase Cloud Functions Firestore 触发器产生:错误:7 PERMISSION_DENIED:权限缺失或不足 - Firebase Cloud Functions Firestore Trigger produces: Error: 7 PERMISSION_DENIED: Missing or insufficient permissions Firebase 云消息未显示服务器密钥 - Firebase Cloud Messaging not showing Server Key Firebase 云消息 (FCM) Api Azure 通知中心的密钥 - Firebase Cloud Messaging (FCM) Api Key for Azure Notification Hub 在哪里可以找到 Firebase Cloud Messaging 的 API KEY? - Where can I find the API KEY for Firebase Cloud Messaging?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM