How to Create Topic in Fcm Notifications

How To Create Topic in FCM Notifications

First, given that IID_TOKEN is your registration token and TOPIC_NAME is the topic you want to create, you need to create topic by making a POST request to

https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME

And to check your created Topics make a GET request on this URL

 https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true

and insert your API_KEY in your Request HEADERS

Authorization: key=YOUR_API_KEY

Your topic will take up to 1 day to show up in Firebase console so for testing you can make curl request or use sofware like Advanced REST client

I want to create topic in Firebase console

With FirebaseMessaging first you will need to subscribe to a topic and whenever you send a message with respect to the topic, all the users subscribed to the topic will get the notification.
Please refer to Send Messages using topic in Firebase

Lets take a example:

I am using a famous books app where there are multiple books listing and I liked a book named 'XYZ' and I want to get notified whenever there is anything related to book XYZ. So I will subscribe to topic XYZ and server will broadcast a notification using the topic 'XYZ' and as I have subscribed to topic 'XYZ' I will get the respective message.

How to create topic in firebase cloud messaging

There is no separate operation to create a topic. Topics are automatically creates when a user first subscribes to them, or when a first message is sent to them.

How create notification topic for Firebase and use this?

There is no need to create a service when you want to subscribe to a topic. Just call anywhere in your app:

FirebaseMessaging.getInstance().subscribeToTopic("news");

Also see the section Subscribe the client app to a topic in the Firebase documentation.

Create a topic in Firebase from Android

Solved! When you do FirebaseMessaging.getInstance().subscribeToTopic("newTopic"), if the topic called "newTopic" doesn't exits, it is created and the user is subscribed to that new topic.

Create a TOPIC on firebase using PHP

Firebase message topics cannot be created on their own - they start to exist as soon as one device is subscribed to them and stop to exist when no device is subscribed.

From a server perspective, you can send a message to any topic of your choice (as long as the name by itself is valid). Firebase will accept the message in any case and deliver it to all subscribed devices (0 if no device is subscribed).

If you want to publish the available topics provided by your application to all the clients of your application, you need to do this separately from Firebase (e.g. with an API endpoint).

If you rename a topic in your application, you will need to re-subscribe the clients to the new topic (and preferably unsubscribe them from the old one). You can do this with the Instance ID API (https://developers.google.com/instance-id/reference/server) per instance. Please note that it‘s currently not possible to retrieve a list of all devices subscribed to a topic. It‘s also not possible to rename a topic and move all subscribed devices from one topic to another. This is business logic that you would have to implement on your application‘s level.

The Firebase Admin SDKs provide methods to manage topic subscriptions, see https://firebase.google.com/docs/admin/setup for a list of official SDKs.

If you need/want to stick to PHP, there‘s an unofficial Admin SDK at https://github.com/kreait/firebase-php (Disclaimer: I‘m the maintainer)

Create and send cloud messages to Topic in Firebase

One option, if using Node.js, is to use node-gcm (https://github.com/ToothlessGear/node-gcm).

For example:

  var gcm = require('node-gcm');

var sender = new gcm.Sender(senderKey);

var message = new gcm.Message();
message.addNotification('title', title);
message.addNotification('body', body);

sender.send(message, { topic: "/topics/" + topic }, function (err, response) {
if (err) console.error(err);
else console.log(response);
});


Related Topics



Leave a reply



Submit