如何从 Firebase 获取所有设备令牌? [英] How to get all of device tokens from Firebase?

查看:21
本文介绍了如何从 Firebase 获取所有设备令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Firebase 获取设备令牌(FCM 注册令牌)?

How to get device tokens (FCM registration tokens) from Firebase?

我正在使用 firebase 制作移动应用程序,并使用 node.js 制作其服务器.

I'm making mobile app using firebase and its server using node.js.

我想从服务器发送 push notification 消息,但我不知道如何获取设备令牌.

I want to send push notification message from server, but I don't know how to get devices token.

  1. 如何从外部服务器获取设备令牌?我现在正在使用 Firebase 管理 SDK.

  1. How to get device tokens from external server? I'm using Firebase admin SDK now.

设备token是不是只有app连接fcm服务器时才会生成?

Is the device token only generated when the app is connected fcm server?

当用户首次运行应用并注册 FCM 服务器时,我应该将令牌保存到另一个数据库吗?

Should I save token to another database when user first run the app and register FCM server?

推荐答案

1.如何从外部服务器获取设备令牌?我现在正在使用 Firebase 管理 SDK.

目前没有 API 可以从服务器端检索您的应用的所有注册令牌.开发者(您)有责任将注册令牌发送并存储到您的应用服务器,该令牌是从客户端应用端生成的.

There is currently no API to retrieve all the Registration tokens for your app from the Server side. It's the developer's (you) responsibility to send and store the Registration token to your App Server, which is generated from the Client App side.

2.设备token是不是只有app连接FCM服务器时才会生成?

文档几乎涵盖了这一点(参见也是我的回答这里):

The documentation pretty much covered this (see also my answer here):

在您的应用首次启动时,FCM SDK 会为客户端应用实例生成一个注册令牌.

On initial startup of your app, the FCM SDK generates a registration token for the client app instance.

从技术上讲,它无法连接到 FCM 服务器.它连接到 FirebaseInstanceID 服务(通过 SDK),进而生成注册令牌.

It doesn't technically get connected to the FCM Servers. It connects to the FirebaseInstanceID service (via the SDK), which in turn generates the Registration Token.

3.当用户第一次运行应用程序并注册 FCM 服务器时,我应该将令牌保存到另一个数据库吗?

正如我在 #1 中提到的,您应该将其保存在可以轻松访问以发送消息的位置.

As I mentioned in #1, you should save it where you can easily access it to send a message.

这篇关于如何从 Firebase 获取所有设备令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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