How To Create Topic in FCM Notifications

旧时模样 提交于 2019-11-26 23:39:51

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");
Moh'd Awad

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

Abhishek

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!