Closed naumanahmad17 closed 6 years ago
same here, any solutions folks? it work at console notification, but not node :(
can you please share the payload ?
app.js
...
var admin = require("firebase-admin");
var serviceAccount = require('./config/serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});
var registrationToken = 'dMVUN5CVhH8:APA91bHNFX69huyYeyFa0gsptEHezZwTIrtiGpStyoS3CCue_CBxNPIpBA_MXPJfhQhiZI-I_i901Z7FAZHwBr67KZGDftoW-hQRG22joDLTV5mxDI9znMRE2aBujYl93_EjxW-L8boS';
var payload = {
data: {
title: "hello",
body: "world"
}
};
admin.messaging().sendToDevice(registrationToken, payload)
.then(function(response) {
console.log('Successfully sent message:', response);
})
.catch(function(error) {
console.log('Error sending message:', error);
});
...
console :
Successfully sent message: { results: [ { messageId: '0:1512568973984718%e05724c6f9fd7ecd' } ],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 6341110490948248000 }
im preety sure im following official firebases guide, but its not working at all(sigh)
var payload = {
notification: {
title: 'Title of test push notification',
body: 'Body of test push notification',
click_action:"FCM_PLUGIN_ACTIVITY"
},
data: {
orderId:"123",
pickLocation:"g10",
dropLocation:"f10 ",
orderType:"Posted"
}
};
you are doing it the wrong way you are sending data message you need to send notification object along the data message.
the following link will help you understand the difference between Notification message and data messages.
https://firebase.google.com/docs/cloud-messaging/concept-options
just add the notification object and it will do the magic :)
AS @naumanahmad17 pointed out, the automatic notification generation is through the notification object in the payload.
Use the data object only when you need to push more "data" into your background service.
thankyou folks! i understand now, and make code works :>
device_token eT9LUtfEQRe1htdCSEVZIy:APA91bED2CktD_qPhQOJTEhDNv2Jd_soLsVnfBbtAzTj6m6Gl45JAHtOfTGUrUL0wkK5IUJoWKpygiffMLFVXkUZPeFcWqRR4OKHOPdSWFOCwmosnXH853l9Ddt2EWmtmrxGMuZd1hVi 0|index | Notification { 0|index | results: [ { error: [FirebaseMessagingError] } ], 0|index | canonicalRegistrationTokenCount: 0, 0|index | failureCount: 1, 0|index | successCount: 0, 0|index | multicastId: 8352222041017097000 0|index | }
when this error we get kinldy help me?
@Sohailze
I suggest to use firebase-admin-node instead.
as mentioned "kind of deprecated" on very top of readme file, firebase-admin-node
can now send push easily.
Successfully sent message: { results: [ { messageId: '0:1511508709940437%6f2857526f285752' } ], canonicalRegistrationTokenCount: 0, failureCount: 0, successCount: 1, multicastId: 5428886452395349000 }
i put own server details.when i try to send notification using firebase console it successfully send notification but i am unable to send notification using fcm-node.