FCM 推送通知:MismatchSenderId
FCM Push Notification: MismatchSenderId
美好的一天,
我正在尝试使用来自 FCM 的 URL 来发送消息:
https://fcm.googleapis.com/fcm/send
header 的
Authorization value of **key:*Key from Firebase Console***
Content-Type: **application/json**
body 包括:
{
"to" : "MyKey generated",
"notification" : {
"body" : "Hey",
"title" : "Hey"
}
}
但我总是收到这样的结果:
{
"multicast_id": 7942550122547405787,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "MismatchSenderId"
}
]
}
我得到的服务器密钥来自这里:
Server Key
我的 URL 参考资料是 FCM 服务器中的文档。
我正在 Postman 中对此进行测试。我错过了什么?谢谢
根据文档
A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.
听起来您正在尝试向与发件人 ID 无关的 ID 发送推送通知。你应该验证你在正确的地方有正确的密钥
header一定是这样的
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
检查服务器密钥的有效性
api_key=YOUR_SERVER_KEY
curl --header "Authorization: key=$api_key" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
如果一切正常,那么您需要重新检查 senderId
您的 Android 应用上的 Google 服务似乎配置不正确。
登录到 Firebase 控制台,打开您的项目(单击齿轮图标)。在常规选项卡下,向下滚动到 "Download the latest config file" 并单击按钮下载 google-services.json(应包括正确的项目和发件人 ID)
将此发送给您的移动开发人员以包含在应用程序中,一旦应用程序发送了有效的推送令牌,请再次尝试发送。
此错误是由于令牌无效
我解决了这个问题,正确输入令牌
通过 POSTMAN
发布 FCM
授权:key=YOUR-SERVER-KEY
内容类型:application/json
现在点击 Body
而不是 select Row
并添加值作为对象,如下所示
确保行在 JSON(application/json)
{
"to": "cpa8cZPjq-w:APA91bF122f1Rnhu9v47bL
YMajaNTHAIU5SzItDwTy9o2MCIveG0PlK78VPvp3d
CqjwnUKZ4
ngi1trSyM3_aXttW62iknFfbPGtjRLhZr6wq-3qFdboz8gzdOGPz**********",
"notification": {
"body": "Hello",
"title": "This is test message."
}
}
POST /fcm/send HTTP/1.1
主持人:fcm.googleapis.com
此问题仅表示服务器和客户端使用了 2 个不同的 firebase 项目。当您不小心按下错误的键并混淆了您的开发、暂存或生产环境时,很可能会发生这种情况。
修复步骤:
- 检查您的服务器,确保 firebase admin / fcm 中的密钥与您的目标环境匹配
- 检查您的客户端,确保它使用相同的目标环境生成推送令牌
您可以通过在您的 firebase 控制台中使用生成的推送令牌发送测试推送通知来确认针对服务器的客户端环境。只有在正确的 Firebase 项目中使用了推送令牌,您才会收到测试通知。
美好的一天,
我正在尝试使用来自 FCM 的 URL 来发送消息:
https://fcm.googleapis.com/fcm/send
header 的
Authorization value of **key:*Key from Firebase Console***
Content-Type: **application/json**
body 包括:
{
"to" : "MyKey generated",
"notification" : {
"body" : "Hey",
"title" : "Hey"
}
}
但我总是收到这样的结果:
{
"multicast_id": 7942550122547405787,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "MismatchSenderId"
}
]
}
我得到的服务器密钥来自这里:
Server Key
我的 URL 参考资料是 FCM 服务器中的文档。
我正在 Postman 中对此进行测试。我错过了什么?谢谢
根据文档
A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.
听起来您正在尝试向与发件人 ID 无关的 ID 发送推送通知。你应该验证你在正确的地方有正确的密钥
header一定是这样的
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
检查服务器密钥的有效性
api_key=YOUR_SERVER_KEY
curl --header "Authorization: key=$api_key" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
如果一切正常,那么您需要重新检查 senderId
您的 Android 应用上的 Google 服务似乎配置不正确。
登录到 Firebase 控制台,打开您的项目(单击齿轮图标)。在常规选项卡下,向下滚动到 "Download the latest config file" 并单击按钮下载 google-services.json(应包括正确的项目和发件人 ID)
将此发送给您的移动开发人员以包含在应用程序中,一旦应用程序发送了有效的推送令牌,请再次尝试发送。
此错误是由于令牌无效 我解决了这个问题,正确输入令牌
通过 POSTMAN
发布 FCM
授权:key=YOUR-SERVER-KEY
内容类型:application/json
现在点击 Body
而不是 select Row
并添加值作为对象,如下所示
确保行在 JSON(application/json)
{
"to": "cpa8cZPjq-w:APA91bF122f1Rnhu9v47bL
YMajaNTHAIU5SzItDwTy9o2MCIveG0PlK78VPvp3d
CqjwnUKZ4
ngi1trSyM3_aXttW62iknFfbPGtjRLhZr6wq-3qFdboz8gzdOGPz**********",
"notification": {
"body": "Hello",
"title": "This is test message."
}
}
POST /fcm/send HTTP/1.1
主持人:fcm.googleapis.com
此问题仅表示服务器和客户端使用了 2 个不同的 firebase 项目。当您不小心按下错误的键并混淆了您的开发、暂存或生产环境时,很可能会发生这种情况。
修复步骤:
- 检查您的服务器,确保 firebase admin / fcm 中的密钥与您的目标环境匹配
- 检查您的客户端,确保它使用相同的目标环境生成推送令牌
您可以通过在您的 firebase 控制台中使用生成的推送令牌发送测试推送通知来确认针对服务器的客户端环境。只有在正确的 Firebase 项目中使用了推送令牌,您才会收到测试通知。