flutterfirebase-cloud-messaging

Flutter Firebase apiKey, appId, messagingSenderId and projectId


I need to use firebase_messaging to send message from my backend to my flutter apk.

When initialize firebase, these are the 4 keys essential in the FirebaseOptions

apiKey : Is this the Server Key found in FCM?

appId : Where can I find this key?

messagingSenderId : Sender ID FCM

projectId : Where can I find this?

Besides, in order for me to send message to a single user. I need to tell Firebase who am I right? May I know which ID shall I use?

Thx


Solution

  • When you register with firebase you obtain the push notification token. This token is used to send a notification to the device the app is installed on.

    Assuming you already initialized firebase app in flutter, and you added the google-services.json in your app. You can obtain your push notification token in the following way:

    messaging = FirebaseMessaging.instance;
        messaging.getToken().then((value){
            print(value); //this is the push notification token
    });
    

    You can also test that you are able to receive the notification on the app from the firebase console. You can send a notification to the app under Compose notification section in the firebase console. It only requires the notification token you obtained from the app.