How To Create Topic in FCM Notifications

后端 未结 4 2054
小蘑菇
小蘑菇 2020-11-28 19:51

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 ? <

相关标签:
4条回答
  • 2020-11-28 20:25

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

    0 讨论(0)
  • 2020-11-28 20:32

    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");
    
    0 讨论(0)
  • 2020-11-28 20:33

    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

    0 讨论(0)
  • 2020-11-28 20:37

    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

    0 讨论(0)
提交回复
热议问题