管理 FCM 设备组 [英] Managing FCM device groups

查看:25
本文介绍了管理 FCM 设备组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清楚如何使用 REST API 从应用服务器管理 FCM 设备组.

AFAIK 这些是更新的文档:https://firebase.google.com/docs/cloud-messaging/android/device-group#managing_device_groups

这是我已经可以做的:

  • 使用一些设备令牌创建一个新的设备组
  • 将设备令牌添加到现有设备组

这就是我不知道该怎么做,因为文档中没有提到它:

  • 根据notification_key_name查询设备组是否已经存在.

    解决方法 1:如果我尝试使用 notification_key_name 创建一个组已经存在然后我收到一个错误告诉我,但这似乎就像一种非常 hacky 的方式来找出答案.

    解决方法 2:自己将这些信息存储在其他地方.

  • 找出属于设备组的设备令牌 (registration_id).

    解决方法:和以前一样,自己将这些信息存储在其他地方.

  • 从设备组中删除设备令牌 (registration_id).

    解决方法:无.

  • 删除设备组.

    解决方法:无.

谢谢!

解决方案

  • 根据notification_key_name查询设备组是否已经存在.

您的第二个解决方法是可行的方法.您应该将其存储在您的应用服务器中,与您还存储注册令牌的位置相同.

<小时><块引用>
  • 找出哪些设备令牌 (registration_id) 属于设备组.

与上述解决方法相同.您必须在您的应用服务器上管理这些详细信息.管理这些细节是开发人员的责任.如果注册设备被移除,则匹配操作,您也必须将其从应用服务器中移除.

<小时><块引用>
  • 从设备组中删除设备令牌 (registration_id).

我不确定您在这里需要什么.文档 有关于从设备组中删除注册令牌的详细信息:

<块引用>

在设备组中添加和删除设备

要在现有组中添加或删除设备,发送一个 POST 请求,将 operation 参数设置为 addremove,并提供用于添加或删除的注册令牌.

注意:如果您从设备组中删除所有现有的注册令牌,FCM 会删除该设备组.

HTTP POST 请求

例如,要将注册 ID 为 51 的设备添加到 appUser-Chris,您可以发送以下请求:

<代码>{"操作": "添加","notification_key_name": "appUser-Chris","notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",registration_ids":[51"]}

回复格式

添加或删除设备的成功请求会返回如下所示的 notification_key:

<代码>{"notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"}

注意:添加/删除注册令牌不需要notification_key_name,但包含它可以防止您意外使用不正确的notification_key>.

<小时><块引用>

  • 删除设备组.

来自上面文档中的注释:

<块引用>

注意:如果您从设备组中删除所有现有的注册令牌,FCM 会删除该设备组.

I'm trying to figure out how to manage FCM device groups from an app server by using the REST API.

AFAIK these are the updated docs: https://firebase.google.com/docs/cloud-messaging/android/device-group#managing_device_groups

Here's what I can already do:

  • Create a new device group with some device tokens
  • Add device tokens to an existing device group

And this is what I just can't figure out how to do since there's no mention of it in the docs:

  • Query whether a device group already exists, based on its notification_key_name.

    Workaround 1: if I try creating a group with a notification_key_name that already exists then I get an error telling me so, but that seems like a very hacky way to find out.

    Workaround 2: Store that information by myself somewhere else.

  • Finding out which device tokens (registration_id) belong to a device group.

    Workaround: as before, store that information by myself somewhere else.

  • Remove device tokens (registration_id) from a device group.

    Workaround: none.

  • Remove a device group.

    Workaround: none.

Thanks!

解决方案

  • Query whether a device group already exists, based on its notification_key_name.

Your 2nd workaround is the way to go. You should store it in your App server, same where you also store the Registration Tokens.


  • Finding out which device tokens (registration_id) belong to a device group.

Same as the workaround above. You have to manage these details on your App Server. It is the developer's responsibility to manage these details. Matching the actions if the registration device is removed, you'll have to remove it from your App Server as well.


  • Remove device tokens (registration_id) from a device group.

I'm not sure what you need here. The documentation have details on removing registration tokens from the device group:

Adding and removing devices from a device group

To add or remove devices from an existing group, send a POST request with the operation parameter set to add or remove, and provide the registration tokens for addition or removal.

Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

HTTP POST request

For example, to add a device with the registration ID 51 to appUser-Chris, you would send this request:

{
   "operation": "add",
   "notification_key_name": "appUser-Chris",
   "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
   "registration_ids": ["51"]
}

Response format

A successful request to either add or remove a device returns a notification_key like the following:

{
   "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
}

Note: notification_key_name is not required for adding/removing registration tokens, but including it protects you against accidentally using the incorrect notification_key.


  • Remove a device group.

From the note in the docs above:

Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

这篇关于管理 FCM 设备组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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