Count subscribers of a topic in Firebase Cloud Mes

2020-02-01 20:13发布

What I want to do with my app is this: users can select different interests and as soon as there are more than ~5 people interested in the same thing, I want to send them a notification.

I thought Firebase + Topics would be a good choice for this.

But how do I find out how many people have subscribed to a topic?

2条回答
叛逆
2楼-- · 2020-02-01 20:47

There is no direct way of doing this. Your only two options are:

  1. Using stored deviceIDs in your own DB, manually script to retrieve each users subscriptions.
  2. Already track in your own DB each users deviceIDs AND every topic they subscribe to.

There are so many problems with both of these methods though. It's frustrating topic managmenet doesn't already exist in FCM Console. I wrote Google a feature request for FCM Cloud Notification Topic Management and this is the response I got:

We're aware that many developers, such as yourself, would like to have this topic management. There's actually an existing feature request regarding this. However, I can't provide any details or timelines as to when this will be available.

查看更多
一夜七次
3楼-- · 2020-02-01 21:00

There is no available API to check how many subscribers a topic has. (see my answer here)

You'll have to implement the mapping on your server-side, saving the name of the topics and adding in the list of subscribers. Upon subscription, add the new subscriber, check the count (see if it's within your preferred number), then trigger a notification.

查看更多
登录 后发表回答