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?

AL.
  • 36,815
  • 10
  • 142
  • 281
Butterkekskrumel
  • 313
  • 3
  • 14
  • Possible duplicate of [Firebase Cloud Messaging - Check existing or available Topics](http://stackoverflow.com/questions/39623742/firebase-cloud-messaging-check-existing-or-available-topics) – AL. Nov 29 '16 at 08:53

3 Answers3

16

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.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Is this still the case(as this answer is 1 year old) or any API has been implemented? – Yesha Jul 06 '18 at 06:12
  • @Yesha There still is no update so far, so yes. This is still the case. – AL. Jul 06 '18 at 08:14
  • Okay. Thank you! – Yesha Jul 06 '18 at 08:23
  • 3
    3 year old answer, is this still the case :) – Okan Kocyigit Feb 21 '19 at 07:55
  • 2
    In some cases, server side solution is near to impossible. – Mohammad Ali Akbari Aug 01 '19 at 18:21
  • I was storing all user deviceIDs in my db but a coding error overwrote every deviceID with an identical deviceID. And now, due to changes in how we register users to specific topics we need to get all devIDs from all the old topicIDs and register all the same deviceIDs to the new topicIDs. This won't necessarily help us correct our DB issue, but at least all the users who had subscribed to old topics (no longer being used) will still get messages to the new topicIDs. The problem is, how do we get all registered devIDs to the old topics in order to register those IDs to the new topics? – rolinger Oct 13 '19 at 19:24
  • @rolinger I don't think there's a one-step fix for this. A solution that came to mind however would be to get all device IDs again, get the corresponding tokens, use the [Instance ID API](https://developers.google.com/instance-id/reference/server#get_information_about_app_instances) to check the list of topics they are subscribed to, then subscribe to new ones as needed. This can be expensive depending on how many you would need to "migrate". Cheers! – AL. Oct 14 '19 at 06:55
  • @AL - yeah, thats the problem, since we don't have the correct deviceIDs for each user we have no way of pulling what topics they are subscribed to. Our app does auto update our DB with the users deviceID every time the user turns on the app, however, not every user turns on the app every day, or every week or month - and as we have learned, sometimes several months. The issue overwriting the users deviceID happened about 1 month ago and to date we have only recovered about 15% of the correct deviceIDs. – rolinger Oct 14 '19 at 12:45
  • @AL. how do we go about notifying % of the subscribers of a topic? – vincent Jan 23 '20 at 08:08
  • @vincent AFAIK, you cant target the topic subscribers by %. It's all or nothing. – AL. Jan 23 '20 at 19:46
  • count up, 4-year-old answer, is it still the case? :D – Tran Ho Apr 30 '20 at 14:38
  • 1
    @TranHo Yes. No API available for this yet. – AL. Apr 30 '20 at 16:47
  • 5 year old answer. Is there any built in solution yet or any plans to do this? – MadMac Aug 03 '21 at 03:20
  • 1
    @MadMac I haven't dabbled with FCM for a time, but I haven't heard of any updates about this so far. Cheers! – AL. Aug 03 '21 at 03:44
6

U can use this to get number of subscribers :

Copy as a curl. Use that to get subscribers list enter image description here

Reference: https://gist.github.com/timrijckaert/218be90541a7285e21455fafa2962dea

1

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.

rolinger
  • 2,787
  • 1
  • 31
  • 53