How to Access The Firebase Topics a User Is Subscribed To

Firebase: Get list of users subscribed to a topic

There is no API to get a list of the tokens that are subscribed to a specific topic.

See:

  • Count subscribers of a topic in Firebase Cloud Messaging
  • How to know whether a user has subscribed to a topic in FCM?
  • List of clients who have registered for a topic in FCM

Is there anyway to access the Firebase Topics a user is subscribed to?

FCM topic subscriptions are based on an application's Instance ID, so when you subscribe or unsubscribe to or from a topic the IID is used.

You can use the Instance ID API to get information about a particular IID, this information includes the topics that the IID is currently subscribed to. See the reference

Android/Firebase - Check to see if you are subscribed to topic

There is currently no way to check on the client side if they are subscribed to a topic.

The behavior for subscribeToTopic is it would immediately subscribe to the specified topic, if it fails, it would retry on it's own (unless your app was killed). See my answer here.

I think that forcing the onTokenRefresh call just to make sure that subscribeToTopic is too much. You could simply just call it in your initial activity if you want, that way, everytime the app starts, it sends the subscription request.

Subscribe a user to a topic in Firebase when uid has changed

The token you're referring to is the device registration token. It can change in the following events:

  • The app deletes Instance ID
  • The app is restored on a new device
  • The user uninstalls/reinstalls the app
  • The user clears app data

In each of these cases you need to get hold of the new registration token, and subscribe it to the topics you care about. Hopefully, all the above events are rare for any given user, so you don't have to do that too often.

Now it seems you represent a chat (I assume this is like a specific conversation or a chatroom in your app), with a topic. So your topics can vary among users. This means you have to also keep track of the topics for each user independently. Store the list of chats/topics for each user, keyed by their unique UIDs in the database. UIDs are constant throughout, so you don't have to worry about them changing over time.

Get all subscribed topics from firebase cloud messaging

I have searched Android API, asked questions for the same on SO but din't find anything. There is nothing in Android API to get all topics of a specific token.

However, you can do it through a GET request

HTTP GET Request

https://iid.googleapis.com/iid/info/<TOKEN>?details=true
Content-Type:application/json
Authorization:key=AAA....i1nM:APA9.....81gTPXCE55....JLPEG0wZobG_ile8lI35JTzHYE5MC..BmDD_Cxj5OxB1Yh....Rs5lo3UwLNL9h-WcocGV....b5bYWNI55kzNsrHK-7GljUDtMn

TOKEN in url : FirebaseInstanceId.getInstance().getToken(senderId, scope);

key : can be found in firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key

Note: Be careful when finding key, dont use web api key its different.

senderId can be found in Settings -> Cloud Messaging -> Sender ID

scope is usually "FCM"

Count subscribers of a topic in Firebase Cloud Messaging

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.

Is there any functions to check topic subscription or un-subscription status in Firebase Cloud Messaging?

Unfortunately, there is no direct API available as of the moment to check the subscriptions of a specific user on the Client Side. You'll only be able to check it using the Instance ID API.

However, perhaps you can implement something in your App Server to have the list of subscriptions the user has, and have it reflect in your Client App.



Related Topics



Leave a reply



Submit