【问题标题】:FCM Node JS Server,FCM 节点 JS 服务器,
【发布时间】:2018-10-24 15:30:01
【问题描述】:

您好,我正在使用 Node JS 和 Firebase SDK,

我正在尝试发送 FCM 通知,如文档所述:https://firebase.google.com/docs/cloud-messaging/admin/send-messages?hl=es-419

我的代码:

function testMessage(){
    let token="f8mNlJq4VOY:APA91bF5_8ldOZEm34ajCfNx7hZ9_LhjUBQFDwZbtSnCNEzb1bEtMsXKlM8upyicvmnJ92xELZzDSxTMaeZrCrrau"
    let message={
         notification: {
    title: "Account Deposit",
    body: "A deposit to your savings account has just cleared."
  },
         data: {
    score: '850',
    time: '2:45'
  },
  token:token
    };
    admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });
}

但是当我执行时,这会显示这个错误:

发送消息时出错:{ 错误:请求包含无效参数。 在 FirebaseMessagingError.FirebaseError [作为构造函数] (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:39:28) 在 FirebaseMessagingError.PrefixedFirebaseError [作为构造函数] (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:85:28) 在新的 FirebaseMessagingError (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:241:16) 在 Function.FirebaseMessagingError.fromServerError (C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\utils\error.js:271:16) 在 C:\Users\Daniel\Documents\Monitora\Demos\BackEnd\APIMonitora\node_modules\firebase-admin\lib\messaging\messaging-api-request.js:149:50 在 在 process._tickCallback (internal/process/next_tick.js:188:7) errorInfo: { code: 'messaging/invalid-argument', 消息:“请求包含无效参数。” }, codePrefix: '消息' }

SDK 它的加载和依赖项正在工作。 你能帮我解决它吗?

【问题讨论】:

  • 这是我的错误,我的数据库中字符串的限制不存储字段的所有内容,并导致该错误:

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


【解决方案1】:

对不起,这是我的错误, 我的数据库中字符串的限制不存储解决此问题的所有 ID,代码看起来:

function testMessage(){
    let registrationToken ='f8mNlJq4VOY:APA91bF5_8ldOZEm34ajCfNx7hZ9_LhjUBQFDwZbtSnCNEzb1bEtMsXKlM8upyicvmnJ92xELZzDSxTMaeZrCrrau-S0mmNdMC18Mp3rwLnUGy-cXM8caoiCJQjEpDDy6FChDwtmO3n2';
    let message={       
    notification: {
    title: "Portugal vs. Denmark",
    body: "5 to 1"
     },
        data: {
    score: '850',
    time: '2:45'
        },
  token: registrationToken

};
admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });
} 

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 2016-09-15
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 2016-06-20
    相关资源
    最近更新 更多