"error" : "MismatchSendedId" 尝试发送 Web 推送通知时

"error" : "MismatchSendedId" when trying to send a Web Push notification

我正在关注此 guide 以了解网络推送实施。我一直按照指南进行操作,直到在使用 curl 发送通知时遇到问题:

curl --header "Authorization: key=<PUBLIC_API_KEY>" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"<SUBSCRIPTION_ID>\"]}"

我用我的 Firebase 云消息传递密钥和在浏览器上接受通知时生成的订阅 ID 更改了 API 密钥和订阅 ID。

执行 curl 时仍然出现此错误:

{"multicast_id":8346257587601342490,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

我发现此错误与 android 推送通知有关,但与网络推送无关,因此其他答案对我的问题没有用。

有人遇到过这个问题吗?我错过了什么?

这意味着 service worker 安装与生成 API 密钥的 GCM 发件人不同的 GCM 发件人相关联。

来自 Pushpad troubleshooting:

  • Make sure that you have created and linked the manifest.json
  • Check that you have entered correctly the gcm_sender_id in the manifest.json
  • Check that you have entered correctly the GCM API key

如果一切正确,您也可以在设置正确后尝试取消订阅并重新订阅gcm_sender_id

我也遇到了同样的事情。即使在重新检查了十几次后,清单已正确写出并设置并且 API_KEY 和 registration_ids 是正确的。 但我现在注意到问题是我没有复制整个 url link。 例如,如果您的端点 url 是: 端点:https://android.googleapis.com/gcm/send/c_hMYQ0IJEg:APA91bHugFROB5EKLlwFKPjc7lRs_YZ7nBV655oftqdKPtzsmoz149d1BLVntgMpRnLHGqTVn6W7n7je4SoezFhfbUMdwxAot

那么 subsctionID 将是 "c_hMYQ0IJEg:APA91bHugFROB5EKLlwFKPjc7lRs_YZ7nBV655oftqdKPtzsmoz149d1BLVntgMpRnLHGqTVn6W7n7je4SoezFhfbUMdwxAot"。

我一直只使用 "APA91bHugFROB5EKLlwFKPjc7lRs_YZ7nBV655oftqdKPtzsmoz149d1BLVntgMpRnLHGqTVn6W7n7je4SoezFhfbUMdwxAot" 中的最后一部分,我想这就是我遇到错误的原因。