Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occurred when trying to authenticate to the FCM servers

An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions enter image description here

like image 789
UA DEV Avatar asked Aug 30 '25 15:08

UA DEV


2 Answers

For solving this problem I took the following steps:

  1. open Google Cloud Platform Dashboard
  2. Go to API and Services
  3. Enable API and Services
  4. Search for Cloud Messaging
  5. Turn on the cloud messaging and Firebase cloud messaging API.
like image 71
Peshraw Hasan Avatar answered Sep 02 '25 10:09

Peshraw Hasan


By default Firebase uses Firebase Cloud Messaging API (V1) so you need to use this api instead of legacy one

for Firebase Cloud Messaging API (V1) :

const data = {
    message: {
      token: registrationToken,
      notification: {
        title: "Notification Title",
        body: "Notification Body ",
      },
      data: {
        Nick: "Mario",
        Room: "PortugalVSDenmark",
      },
    },
  };

  admin.messaging().send(data.message);

for Cloud Messaging API (Legacy) 1.First go to Google Cloud Platform Dashboard and enable Cloud Messaging Service 2. and then you can use like this :

 var payload = {
    notification: {
      title: "This is a Notification",
      body: "This is the body of the notification message.",
    },
  };

  var options = {
    priority: "high",
  };

  var registrationToken ="your device token";
   admin
     .messaging()
     .sendToDevice(registrationToken, payload, options)
    .then(function (response) {
       console.log("Successfully sent message:", response);
     })
     .catch(function (error) {
      console.log("Error sending message:", error);
     });

Firebase Cloud Messaging API (V1) is recommended than Cloud Messaging API (Legacy)

like image 32
Abhishek Ghimire Avatar answered Sep 02 '25 10:09

Abhishek Ghimire