How to create a topic in FCM notifications

I try to use the Firebase-Notification API, the service works fine when I send a downstream message from the console to the application, but how do I send a message to the topic of registered users?

i did on the android side

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

but when I try to send a downstream message from the console to the topic, it says

 This project does not have any topics 

EDIT: I found out that after matching the themes, it takes up to 1 day to display in the Firebase Console.

+54
android firebase firebase-notifications google-cloud-messaging
May 21 '16 at 19:45
source share
4 answers

Firstly, given that IID_TOKEN is your registration token, and TOPIC_NAME is the theme you want to create, you need to create a theme by doing a POST request

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

And to check the threads created, make a GET request at this URL

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

and paste your API_KEY in the HEADERS of your request

 Authorization: key=YOUR_API_KEY 

Your theme will take 1 day to display in the Firebase console, so for testing you can make a request for curling or use software such as the Advanced REST client

+46
May 22 '16 at 15:13
source share
β€” -

This is an alternative way.

If you subscribe the client application to an unused topic, the theme will also be created without calling any request to the firebase URL.

A few hours will also appear in the Firebase Console.

Using a general google example: https://github.com/firebase/quickstart-android/tree/master/messaging , you can confirm the same.

  FirebaseMessaging.getInstance().subscribeToTopic("news"); Log.d(TAG, "Subscribed to news topic"); 
+44
May 24 '16 at 20:07
source share

Firebase takes time to create a new theme in the console. In my case, a new topic was created after 4 hours.

+19
Jul 29 '16 at 7:54
source share

You can create a theme using the http api:

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

1. IID_TOKEN = device registration token, you can find it using the following command on your Android device:

 String IID_TOKEN = FirebaseInstanceId.getInstance().getToken(); 

2.TOPIC_NAME = new topic name

3.Authorization: key = YOUR_API_KEY . Set this parameter in the header. Take a look at the screenshot: Creating a new theme through the Advanced rest client

YOUR_API_KEY: console.firebase.google.com

and send the request, and you will get the http status "OK".

Then you can get information about all your topics in your current project with the following api:

 https://iid.googleapis.com/iid/info/IID_TOKEN?details=true 

here you need to add the authorization key in the request header, and you will get a list of topics: topics with answers

I recommend reading this article on google instance id / server

+17
Sep 13 '16 at 12:37
source share



All Articles