jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 46 forks source link

NotAuthorizedError #5

Closed ghost closed 7 years ago

ghost commented 7 years ago
// Method to generate manager with Q promises
function getFcmManager () {
  var serverKey = API_KEY;
  var fcm = new FCM(serverKey);
  // Manager
  var fcmManager = {
    // Send to device holding token
    send: function (token) {
      return Q.Promise(function (resolve, reject) {
        // Message payload
        var message = {
          "notification":{
            "title": "Notification title",  //Any value
            "body": "Notification body",  //Any value
            "sound": "default", //If you want notification sound
            "click_action": "FCM_PLUGIN_ACTIVITY",  //Must be present for Android
            "icon": "fcm_push_icon"  //White icon Android resource
          },
          "data":{
            "param1": "value1",  //Any data to be retrieved in the notification callback
            "param2": "value2"
          },
            "to": token, //Topic or single device
            "priority": "high", //If not set, notification won't be delivered on completely closed iOS app
            "restricted_package_name": "" //Optional. Set for application filtering
        };
        // Push
        fcm.send(message, function(err, response){
          if (err) {
            console.log("FCM: Something has gone wrong!", err);
            reject();
          } else {
            console.log("FCM: Successfully sent with response: ", response);
            resolve();
          }
        });
      });
    }
  }
  // Return
  return fcmManager;
}
jlcvp commented 7 years ago

Please re-check your apikey in FCM console. Google regenerated some of the keys in a update 2 months ago. Feel free to reopen this as long as you provide more info