Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all subscribed topics from firebase cloud messaging

Using the new FirebaseMessaging it's easy to un/subscribe to topics via:

FirebaseMessaging.getInstance().subscribeToTopic();
FirebaseMessaging.getInstance().unsubscribeFromTopic();

But is there any way to get all topics the current installation is subscribed to ?

like image 860
Andre Classen Avatar asked Jun 23 '16 09:06

Andre Classen


People also ask

How do I get Firebase topics?

Subscribe the client app to a topic Client apps can subscribe to any existing topic, or they can create a new topic. When a client app subscribes to a new topic name (one that does not already exist for your Firebase project), a new topic of that name is created in FCM and any client can subsequently subscribe to it.

How do I get my messages from Firebase?

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console).

Is there a limit on Firebase messaging?

Maximum message rate to a single device For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.

What are the two types of messages in firebase cloud messaging?

Using Firebase Cloud Messaging, we can send three types of messages, i.e., Notification Message, Data Message, and the message with both Notification & Data Payload.


2 Answers

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"

like image 175
Hisham Muneer Avatar answered Nov 02 '22 03:11

Hisham Muneer


For those that would like to test it with command line CURL follow bellow the syntax that I have used:

#curl --location --request GET 'https://iid.googleapis.com/iid/info/yourFCMDeviceToken?details=true' \
--header 'Authorization: Bearer YourProject_CloudMessaging_ServerKey'

Response:

{
    applicationVersion: '4194309',
    application: 'com.domain.app',
    scope: '*',
    authorizedEntity: '913674269572',
    rel: { topics: { topicName: { addDate: '2020-08-19' } } },
    appSigner: 'ae7cbSomeHash23jsdfff34ac7ffd',
    platform: 'ANDROID'
} 
like image 10
Cassio Seffrin Avatar answered Nov 02 '22 04:11

Cassio Seffrin