简体   繁体   English

Firebase Cloud Messaging(FCM)注册令牌服务器端验证

[英]Firebase Cloud Messaging (FCM) registration token server-side validation

I'm updating a backend service that sends push notifications to iOS and Android devices through Firebase Cloud Messaging (FCM) HTTP APIs. 我正在更新一个后端服务,该服务通过Firebase Cloud Messaging(FCM) HTTP API将推送通知发送到iOS和Android设备。

I noticed that we were using the legacy "HTTP Server Protocol" and now i'm trying to port our service to "FCM HTTP v1 API" . 我注意到我们正在使用旧版“ HTTP服务器协议” ,现在我正尝试将我们的服务移植到“ FCM HTTP v1 API”

Sending a notification, in the previous protocol version responses, there were some error messages (see "Unregistered Device") to identify expired registration tokens. 发送通知时,在先前的协议版本响应中,存在一些错误消息 (请参阅“未注册的设备”)以标识过期的注册令牌。 Now I receive a response with a "name" field containing a mysterious "message_id": 现在,我收到一个带有“名称”字段的响应,其中包含一个神秘的“ message_id”:

{ "name" : "projects/{project_id}/messages/{message_id}" }

I've even tried to send some notifications to very old tokens/devices without receiving any error. 我什至尝试将一些通知发送到非常旧的令牌/设备,而不会收到任何错误。

  • How can I detect the registration tokens that are not working anymore using the current version of the APIs? 如何使用当前版本的API检测不再可用的注册令牌?
  • Is there any documentation about the possible "send" API error responses? 是否有关于可能的“发送” API错误响应的文档?
  • Bonus: when were released the current "FCM HTTP v1 API"? 奖励:当前的“ FCM HTTP v1 API”何时发布?

I'm also considering to expire tokens on a time or app usage base. 我还考虑根据时间或应用使用情况使令牌过期。

Thanks in advance. 提前致谢。

The doc says when the request was successful, the response contains an instance of the message. 医生说,当请求成功时,响应包含消息的实例。

https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send

When the token is not available anymore we get a FileNotFoundException (in java) when we want to read the response. 当令牌不再可用时,当我们要读取响应时,将得到FileNotFoundException(在Java中)。 You can simple test this by deleting the app. 您可以通过删除应用程序对此进行简单测试。

The "FCM HTTP v1 API" was announced at the last Firebase Dev Summit: https://firebase.googleblog.com/2017/10/whats-new-at-firebase-dev-summit-2017.html 在上届Firebase开发峰会上宣布了“ FCM HTTP v1 API”: https ://firebase.googleblog.com/2017/10/whats-new-at-firebase-dev-summit-2017.html

You can validate the FCM token by calling the 您可以通过以下方式验证FCM令牌:

(GET) https://iid.googleapis.com/iid/info/YOUR_APP_TOKEN_HERE
[Header] => 'Authorization: key=YOUR_KEY'

Simple and easy. 简单容易。

If token is valid then it will return 200 status code with some more details in JSON format or if it's invalid then status code will be 400 with error detail in JSON format. 如果令牌有效,则它将以JSON格式返回200个状态代码以及更多详细信息;如果无效,则状态代码将以JSON格式返回400个错误详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM