我試圖使用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。