74

I'm trying Firebase-Notification API the service is worked perfect when i send downstream message from console to app, but how to send message to topic registered users ?

i did in android side

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

but when i try send downstream message from console to topic it's says

This project does not have any topics

EDIT : i figured out that after mapping the topic it's take up to 1 day to show up in Firebase Console

Moh'd Awad
  • 1,758
  • 1
  • 12
  • 22

4 Answers4

67

This is an alternate path.

If you subscribe a client app to an unexisting topic then the topic will also be created without having to call any firebase url request.

It' will also take a couple of hours to appear on Firebase Console.

By using google shared 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");
Juan Pablo
  • 1,213
  • 10
  • 15
  • 1
    Thanks for pointing out the expected delay - I'd thought that there may have been a client issue but I suspect that's the problem I'm experiencing. Cheers. – NSTJ Apr 01 '17 at 13:55
  • What should I do if a topic doesn't appear even after 2 days? – Nik Jul 09 '17 at 09:23
  • @jped After 3 more days and 100 more tries and updating to 4.x branch it eventually appeared. I actually think an update solved my problem. – Nik Jul 12 '17 at 10:26
  • `news` or `/topics/news`? – Twitter khuong291 Feb 27 '19 at 12:43
61

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

user229044
  • 232,980
  • 40
  • 330
  • 338
Moh'd Awad
  • 1,758
  • 1
  • 12
  • 22
  • 8
    What is REGISTERATION TOKEN? – xinbenlv Jun 24 '16 at 00:56
  • 9
    fyi: this is the exact same thing as calling `subscribeToTopic()` from a device. The logic is always the same: a topic is created when a device subscribes to it or when a server sends to it. – Frank van Puffelen Jul 08 '16 at 17:21
  • thats too long way – Jemshit Jul 15 '16 at 12:12
  • does anybody know how to unsubcribe from a topic without using batch (`https://iid.googleapis.com/iid/v1:batchRemove`)? – Lea Feb 18 '17 at 22:45
  • Hey I'm stuck at this problem while creating topic in node js. Can you please tell me where's the problem? http://stackoverflow.com/questions/43421040/creating-messaging-topic-on-cloud-function – Doge Apr 15 '17 at 19:48
  • 2
    @Patrick use DELETE https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME – NickUnuchek Sep 15 '17 at 07:56
  • regarding @Patrick @NickUnuchek comments, please note `DELETE` invalidates the `IID_TOKEN`, which is not necessarily desired. `batchRemove` does not. – verboze Jun 28 '18 at 20:44
23

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

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Abhishek
  • 968
  • 10
  • 16
  • 1
    This doesn't really add anything. The function to subscribe to the topic has already been given by the OP in the question. The other one hasn't, but it is not what he asked for. Please consider editing your answer to make it correspond to the question. Thank you! – Fabio says Reinstate Monica Jul 29 '16 at 08:31
  • 2
    This answered my question. I was expecting it to ping instantly. – PGMacDesign Oct 12 '16 at 23:40
23

You can create a topic with http api:

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

1. IID_TOKEN = Device registration token, you can find it with following command on your android device :

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

2.TOPIC_NAME = new a topic name

3.Authorization: key=YOUR_API_KEY. Set this parameter in the header. Look to screenshot: Creating new topic via Advanced rest client

YOUR_API_KEY: console.firebase.google.com

and send request and you will be receive http status "OK".

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

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

here need add Authorization key to header of request and you will be receive your topics list: response info topics

I recommend read this article about Instance ID/Server by Google

SBotirov
  • 13,872
  • 7
  • 59
  • 81