Firebase消息传递缺少MongoDB触发器函数中的验证密钥:

qlvxas9a  于 2023-01-31  发布在  Go
关注(0)|答案(1)|浏览(120)

我需要帮助。我不知道我做错了什么。我尝试从http请求发送推送通知,但我一直得到这个错误:
请求缺少身份验证密钥。请参阅FCM文档的“身份验证”部分,地址为https://firebase.google.com/docs/cloud-messaging/server
我目前正在执行此操作:

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,
  });

我的Web服务器密钥**(云消息传送API(旧版))**我还尝试了API密钥:

bfrts1fy

bfrts1fy1#

这是我的错(headers not header)。但我会把这个答案留给任何使用FlutterMongoDBFirebase消息传递的人。

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,
  });

相关问题