本文介绍了有没有办法根据注册 ID 或通知密钥名称检索现有的 notification_key?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设已经在 Firebase Cloud Messaging 中创建了一个设备组,有没有办法在设备组创建后检索现有的 notification_key?

Assuming that one has created a device group in Firebase Cloud Messaging, is there a way to retrieve an existing notification_key for a device group after it's been created?

有没有办法根据通知键名称或注册 ID 查找 notification_key?

Is there a way to look up the notification_key based on either notification key name or by registration id?

似乎通知密钥仅在创建方法上返回,如果密钥丢失或保存到数据库时出错 - 没有 就不可能向密钥名称添加另一个注册 IDnotification_key 因为它已经存在了.

It seems the notification key is only returned on the create method and if the key is ever lost or errors on saving to the the database - it would be impossible to add another registration id to the the key name without a notification_key since it already exists.

推荐答案

如果您知道创建设备组时使用的 notification_key_name,则可以检索设备组的 notification_key.参考:https://firebase.google.com/docs/cloud-messaging/android/设备组

You can retrieve the notification_key for a device group if you know the notification_key_name that was used when you created it. Ref: https://firebase.google.com/docs/cloud-messaging/android/device-group

使用这个:

https://android.googleapis.com/gcm/notification?notification‌​_key_name=your-key-n‌​ame

参考:https://groups.google.com/forum/#!topic/firebase-talk/ytovugx8XNs

例如:

let options = {
    url: 'https://android.googleapis.com/gcm/notification?notification_key_name=the_name',
    method: 'GET',
    headers: {
        "Content-Type": "application/json",
        "Authorization": "key=" + authorizationKey,
        "project_id": projectId
    }
};

request(options, function (error, response, body) {
    if (!error) {
        res.json(body);
    }
    else {
        res.json(error);
    }
});

我在使用此调用时发现的一件事是返回的 notification_key 总是不同的,但我能够成功地使用它来添加或删除registration_ids.

One thing I found when using this call was that the notification_key returned was always different, but I was able to use it successfully to add or remove registration_ids.

我将从之前的评论中添加一些额外的信息:

I'll add some additional information from comments I made earlier:

  1. 我在设备组方面遇到了很多麻烦.删除设备组的唯一方法是删除它包含的所有通知键.如果您忘记了已添加到设备组的通知键,则无法删除该设备组,因为目前无法获取设备组中的通知键列表.
  2. 设备组是向多个设备发送消息的一种非常好的机制(另一种方法请参见@AL. 的评论).我还将每个设备组的registration_ids 存储在数据库中.这样做的原因是,如果用户为我的应用删除了他们的帐户,我也会删除他们的设备组,以便可以重复使用设备组名称.

这篇关于有没有办法根据注册 ID 或通知密钥名称检索现有的 notification_key?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:37