提供了无效的注册令牌。确保它与客户端应用从FCM注册中获得的注册令牌相匹配

时间:2018-11-28 23:26:46

标签: node.js firebase push-notification apple-push-notifications firebase-cloud-messaging

我从XCode控制台上的客户端iOS应用获得了此代码

enter image description here

Firebase注册令牌:diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h

NodeJS

console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
    to: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
    data: {
        cpeMac: '000000000000',
        type: 'malware'
    },
    notification: {
        title: 'Hello baby',
        body: 'Nice body',
        tag: collapseKey,
        icon: 'ic_notification',
        color: '#18d821',
        sound: 'default',
    },
};


fcm.send(message, function(err, response){
    if (err) {
        console.log("Something has gone wrong!")

        console.log(JSON.stringify(err));

    } else {
        console.log("Successfully sent with response: ", JSON.stringify(response))
    }
})

console.log("END");

结果

运行时

node app.js  

我不断得到

START                                                                                 
END                                                                                   
Successfully sent with response:  {"results":[{"error":{"code":"messaging/invalid-registration-token","message":"Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM."}}],"canonicalRegistrationTokenCount":0,"failureCount":1,"successCount":0,"multicastId":7577724855311354000}

如何进一步调试呢?

1 个答案:

答案 0 :(得分:3)

您的令牌具有一些其他随机字符串,例如 到: 'diWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',

只需从令牌字符串中删除:diWY78iar8s:

console.log("START");
var FCM = require('fcm-node');
var serverKey = require('/Users/bheng/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json')
var fcm = new FCM(serverKey)
var collapseKey = 'new_message';
var message = {
    to: 'APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h',
    data: {
        cpeMac: '000000000000',
        type: 'malware'
    },
    notification: {
        title: 'Hello baby',
        body: 'Nice body',
        tag: collapseKey,
        icon: 'ic_notification',
        color: '#18d821',
        sound: 'default',
    },
};


fcm.send(message, function(err, response){
    if (err) {
        console.log("Something has gone wrong!")

        console.log(JSON.stringify(err));

    } else {
        console.log("Successfully sent with response: ", JSON.stringify(response))
    }
})

console.log("END");

FCM的回复:

Successfully sent with response:  { results: [ { messageId: '0:1543448946734425%479ec0e2479ec0e2' } ],
  canonicalRegistrationTokenCount: 0,
  failureCount: 0,
  successCount: 1,
  multicastId: 6133765431734591000 }