FCM 404“未找到请求的实体". errorCode:“未注册" [英] FCM 404 "Requested entity was not found" errorCode: "UNREGISTERED"

查看:716
本文介绍了FCM 404“未找到请求的实体". errorCode:“未注册"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用WebPush,并且在大多数情况下效果很好.但是,有时-通常在长时间的使用后-用户将收到带有以下JSON响应的404错误:

I am using WebPush in my project and it works well for the most part. However, occasionally - often after a prolonged period of use - a user will receive a 404 error with the following JSON response:

{
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "UNREGISTERED"
      }
    ]
  }
}

似乎正在发生的事是令牌即将到期.函数onTokenRefresh()在很多场合都被引用,但是很少有关于如何实现的文档,当然也没有关于如何测试的文档.一些用户报告说清除缓存将强制刷新令牌.对我来说不是这种情况.

What appears to be happening is that the token is expiring. The function onTokenRefresh() is cited on numerous occasions, but with little documentation on how to implement and certainly none regarding how to test. Some users have reported clearing cache will force a token refresh; this is not the case for me.

我已经有将近6个月的时间遇到​​此问题,并定期检查以查看文档是否有所改进,但是尚无明确的解决方案.

I have had this problem for nearly 6 months, and regularly check back to see if the documentation has improved, but there is no clear solution to this problem.

任何测试的解决方案将不胜感激.我确信还有其他人在使用未充分记录的WebPush通知,并且存在类似问题.

Any solutions to test at this point would be enormously appreciated. I am sure there are others out there using the under-documented WebPush notifications with similar issues.

推荐答案

onTokenRefresh()(现已弃用.使用onNewToken(String s)实现FirebaseMessagingService,请查看其他答案

onTokenRefresh() (now deprecated. Use onNewToken(String s) implementing FirebaseMessagingService, check out this other answer FirebaseInstanceIdService is deprecated) is called every time the application installed gets a new token, whatever the reason it is (for instance, if the user goes to the "Applications" android configuration menu option, selects your application and press "Clear Data", but that is just one reason).

您必须使用此方法来调用后端并更新存储先前令牌的位置,以使后端不再使用它以在令牌过期时向其发送任何消息(从而抛出该令牌). NOT_FOUND/UNREGISTERED错误).

You have to use this method to call your backend and update the places where you stored the previous token, in order for your backend not to use it anymore to send any messages to it as it had been expired (and thus throwing the NOT_FOUND/UNREGISTERED error).

请不要忘记按照文档中的说明在AndroidManifest.xml中添加以下内容:

Don't forget to add the following in your AndroidManifest.xml as stated in the documentation:

在清单中包括以下内容:

Include the following in the manifest:

<service android:name=".YourFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
   </intent-filter>

FirebaseMessagingService的文档:

https://firebase.google.com /docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService

这篇关于FCM 404“未找到请求的实体". errorCode:“未注册"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆