Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Notification & User Id

I'm using Firebase with an Android app (Auth, Database and Notification).

I'm trying to send notification from an external server (in nodejs) so an user can send a notification to another user.

So the android app memorize a list of UserId (the same ids from Firebase Auth) and then send this list to the nodejs server.

With this list, the server contact the url 'https://fcm.googleapis.com/fcm/send', but Firebase returns me a InvalidRegistration because i'm sending a list of userId and not the list of registration token created by firebase notification.

Should I memorize those tokens or there is a way to send notification with the user id ?

(And when I try with a list of tokens, of course it's working.)

var requestData = {
    "registration_ids": userIds, //Problem is here
    "data": {
      "message": "A message"
     }
  };

  request({
      url: "https://fcm.googleapis.com/fcm/send",
      method: "POST",
      json: true,
      headers: {
          "Authorization": "key=firebaseKey",
          "content-type": "application/json",
      },
      json: requestData
  },
  function(err, response, body) {

  });
like image 254
Nicolas D Avatar asked Jun 25 '16 14:06

Nicolas D


People also ask

What is firebase notification?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

What is firebase notification in android?

Firebase Notifications is a free service that enables user notifications for Android and iOS devices. Through the Firebase console, you can send notifications quickly and easily across platforms with no server coding required.

How to send notification through Firebase console?

You can send notification messages using the Notifications composer in the Firebase console. Though this does not provide the same flexibility or scalability as sending messages with the Admin SDK or the HTTP and XMPP protocols, it can be very useful for testing or for highly targeted marketing and user engagement.


1 Answers

Yes, you can. For this you have to register these user Ids instead of device Id token. Then firebase recognized your user Ids.

   @Override
    public void onNewToken(@NonNull String token) {

        super.onNewToken(token);
        Log.d("user_token: ",token);
     

    }
like image 108
Majedur Avatar answered Oct 12 '22 23:10

Majedur