我正在尝试使用Firebase云消息传递使用Postman到网址https://fcm.googleapis.com/fcm/send
进行推送通知。
这是我使用的数据:
method: POST,
headers: {
"Content-Type": application/json,
"Authorization": key=<my_api_key>
},
body: {
"to": "<some_device_key>",
"notifcation": {
"title": "Hi",
"body": "test",
"subtitle": "Jo"
}
}
使用“原始”设置添加正文。问题是我立即得到了答复:
但是当我在标题中省略Authorization
键时,我得到:
<HTML>
<HEAD>
<TITLE>The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
因此,以某种方式将Authorization
添加到标题会使请求变得混乱。可能是什么原因?文档的给定部分没有“身份验证”部分。
对于那些即使您选择传统密钥仍然会遇到此问题的人。为了完成这项工作,我不得不要求另一把钥匙。我做的是:我访问了这个网站:https://console.developers.google.com/apis/credentials/我点击了我的服务器密钥编辑并要求生成一个新密钥。