有没有办法根据注册ID或通知密钥名称检索现有的notification_key? [英] Is there a way to retrieve an existing notification_key based on a registration id or a notification key name?

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

问题描述

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



有没有办法根据通知密钥名称或注册ID来查找 notification_key



看起来通知密钥只是在create方法上返回的,如果密钥丢失或者保存到数据库时出错 - 那么就不可能再添加一个注册ID给键名不含 notification_key ,因为它已经存在。

解决方案

如果知道创建时使用的notification_key_name,则检索设备组的notification_key。参考: https://firebase.google.com/docs/cloud- message / 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',
头文件:{
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。

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


  1. 我在设备组上遇到了很多麻烦。删除设备组的唯一方法是删除它包含的所有通知密钥。如果您忘记了添加到设备组的通知密钥,那么删除该设备组是不可能的,因为目前没有办法获取设备组中的通知密钥列表。

  2. 设备组是一种非常好的将消息发送到多个设备的机制(请参阅@ AL。的另一种方法的注释)。我还在数据库中存储每个设备组的registration_ids。原因是如果用户删除我的应用程序的帐户,我也删除他们的设备组,以便设备组名称可以重复使用。


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?

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

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.

解决方案

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

Use this:

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

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

For example:

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);
    }
});

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. I've had quite a bit of trouble with device groups. The only way to delete a device group is to remove all the notifications keys it contains. If you lose track of a notification key that you have added to the device group then deleting that device group is impossible, as there is no way currently to get a list of the notification keys in a device group.
  2. The device group is a very good mechanism for sending messages to multiple devices (see @AL.'s comment for another method). I also store in the database the registration_ids for each device group. The reason for that is if the user deletes their account for my app I also delete their device group so that the device group name can be reused.

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

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