Search code examples
androidfirebasegoogle-cloud-messagingfirebase-notifications

How To Create Topic in FCM Notifications


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


Solution

  • 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