Search code examples
firebasegoogle-cloud-messagingfirebase-cloud-messagingfirebase-console

How to send a push notification from the Firebase console to a specific GCM/FCM device token ID


In Urban Airship, when I am composing a notification, I can target specific users by searching for a Urban Airship channel_id (device ID):

enter image description here

enter image description here

enter image description here

enter image description here

I sent from Urban Airship the push notification that I am showing above, and I received it successfully. Now I want to do the same thing, send a push notification to a specific device, but now using the Firebase console. The problem is that in Firebase, in the step where I need to specify the target, it only allows me to choose User segment or topic. I was expecting to see a third option: Target specific users (for sending notifications to one or many specific GCM/FCM device token IDs. So my alternative is to add a GCM/FCM device token ID to a topic and then send the push notification to that topic, which is something that I have successfully done before. Nonetheless, that would be a workaround and not the way I would prefer to do this. Is it possible to send push notifications to specific users (by defining the target GCM/FCM device token IDs) from the Firebase console? Thank you.

UPDATE 1: See how the Firebase console (https://console.firebase.google.com/) only shows User segment and Topic as the Target:

enter image description here


Solution

  • By design, the notification feature in the console is for sending out broadcast-type events. Sending user-specific alerts would be more of a programmatic operation done through the API.

    For sending test messages, there is a console tool for this, explained here.

    Note that it is possible to send a notification to one device by subscribing a device to any topic and sending the notification to that topic in the console (keep in mind topics are public and you can't prevent users from signing up to them; fine for testing most likely).

    Another alternative is to send a message via HTTP or curl. Perhaps the best resource for this is the quickstart/messaging example.