使用NodeJ向主题

时间:2017-02-08 20:56:56

标签: node.js firebase firebase-cloud-messaging

我正在尝试使用node-gcm模块将带有NodeJS的FCM发送到我的移动客户端。我不是针对特定设备。但是,我想通过使用主题发送推送,但是当我调用FCM API时,我会收到以下内容:

{ multicast_id: 59360557496141941230,
  success: 0,
  failure: 1,
  canonical_ids: 0,
  results: [ { error: 'InvalidRegistration' } ] }

这是我的代码:

var gcm = require('node-gcm');
var serverKey ='XXXXX';
//var serverKey = 'AIzaSyAS9s5VXlut35NNOkPktqoFzx8EsOxIdK4';
var sender = new gcm.Sender(serverKey);

sendFCM('1231231231');

function sendFCM(number){

    var myTopic="phoneNumber_"+number;
    var message = new gcm.Message({
      data: { key1: 'msg1' }
    });

    //callback style
   sender.sendNoRetry(message, { topic: myTopic }, (err, response) => {
    if (err) console.error(err);
    else console.log(response);
   });

}

1 个答案:

答案 0 :(得分:1)

此行中缺少

/ topics /:

var myTopic =" phoneNumber _" + number;

解决方案:

var myTopic =" / topics / phoneNumber _" + number;