我试图使用node.js构建PushNotification服务器, 我使用了“node-fcm”,但它不适用于我,所以我尝试使用“node-gcm”,但我面临同样的问题,我不知道如何向所有用户发送notifcation?我需要在外地写字(给:)?node-gcm:发送所有设备的PushNotification
这是我的代码:
var gcm = require('node-gcm');
var Sender_ID = '55*****';
var API_KEY = 'my server key';
var sender = new gcm.Sender(API_KEY,{'proxy':'http://username:[email protected]_proxyinternet.com:8080' , timeout: 5000});
var message = new gcm.Message({
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed."
}
});
var registrationTokens = [];
registrationTokens.push(['All']);
sender.send(message, { registrationTokens: 'All' }, function (err, response) {
if (err) console.error(err + ' ERROR');
else console.log(response + ' ELSE');
});
结果是:
{ multicast_id: -1, success: 0, failure: 1, canonical_ids: 0, results: [ { error: 'InvalidRegistration' } ] } Error: Recipient key 'registrationTokens' was provided as an incorrect type. ERROR Process finished with exit code 0
注:我用离子2,我可以从https://console.firebase.google.com/接收notifcation。