如何在应用服务器上检测令牌是否已过期或未注册Firebase FCM通知? [英] How to detect if token is expired or not registred firebase FCM notification on app server?

查看:44
本文介绍了如何在应用服务器上检测令牌是否已过期或未注册Firebase FCM通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将FCM通知从服务器发送到设备:

I am using following code to send the FCM notification from server to device :

    String fcmServerKey = externalConfig.getFcmServerKey();
            CloseableHttpClient httpclient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(HTTPS_FCM_GOOGLEAPIS_COM_FCM_SEND);

            httpPost.setEntity(new StringEntity(message, ContentType.create("application/json")));
            httpPost.setHeader("Authorization", "key=" + fcmServerKey);

CloseableHttpResponse closeableHttpResponse= httpclient.execute(httpPost);

在上面的代码中,当我获得响应对象closeableHttpResponse时,如何检测用于发送此请求的fcm令牌是否已过期或未注册?

In above code when I get the response object closeableHttpResponse, how can I detect wether the fcm token used to send this request is expired or not registered ?

当从Firebase应用程序仪表板中尝试使用fcm令牌将通知发送到设备时,将应用程序从设备中删除后,我在Firebase仪表板上看到Failed,将鼠标悬停在Failed上时看到Unregistered registration token.

When from firebase application dashboard I try sending the notification to a device using its fcm token and After application is removed from device, I see Failed on firebase dashboard, on hovering cursor on Failed I see Unregistered registration token.

如何从api响应对象closeableHttpResponse中检测到Unregistered registration token的上述错误情况?

How can I detect above error situation of Unregistered registration token from api response object closeableHttpResponse ?

推荐答案

使用服务器参考API ,以获取有关设备注册令牌的相关信息.如果响应为空,则表示令牌已过期或未注册.

Use the Server Reference API to get the associated information about the device registration token. If the response is empty, it means that the token is expired or not registered.

示例GET请求

https://iid.googleapis.com/iid/info/nKctODamlM4:...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

示例结果

HTTP 200 OK
  {
    "application":"com.iid.example",
    "authorizedEntity":"123456782354",
    "platform":"Android",
    "attestStatus":"ROOTED",
    "appSigner":"1a2bc3d4e5",
    "connectionType":"WIFI",
    "connectDate":"2015-05-12
    "rel":{
        "topics":{
          "topicname1":{"addDate":"2015-07-30"},
          "topicname2":{"addDate":"2015-07-30"},
          "topicname3":{"addDate":"2015-07-30"},
          "topicname4":{"addDate":"2015-07-30"}
                  }
           }   
  }

这篇关于如何在应用服务器上检测令牌是否已过期或未注册Firebase FCM通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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