我该如何解决使用FCM发送通知的错误?

时间:2019-01-31 23:13:37

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

我正在使用FCM将通知发送到某些设备(Android和iOS),但最近却遇到了这些错误。由于某种原因,代码在某个时候可以正常工作,但是现在我又遇到了错误。

这是我的留言正文:

let message = {
  apns:{
    payload: {
      aps: {
        alert:{
          title: "Title",
          body: "Body"
        }
      }
    }
  },
  token: device.fcmToken
};

这是我用来发送消息的代码(管理员发送消息的示例):

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

令牌是有效的,因为我使用了控制台并且消息通过了 enter image description here

这些是错误:

errorInfo: 
   { code: 'messaging/registration-token-not-registered',
     message: 'Requested entity was not found.' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-payload',
     message: 'Messaging payload contains an invalid "topic" property. Valid properties are "data" and "notification".' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-argument',
     message: 'Request contains an invalid argument.' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-apns-credentials',
     message: 'Invalid APNS credential' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-argument',
     message: 'The registration token is not a valid FCM registration token' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-argument',
     message: 'Value of [aps] must be a non-empty dictionary.' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/invalid-argument',
     message: 'Payload of Apple Push Notification Service must contain an [aps] key.' },
  codePrefix: 'messaging' }
errorInfo: 
   { code: 'messaging/mismatched-credential',
     message: 'Firebase Cloud Messaging API has not been used in project 158024523272 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/fcm.googleapis.com/overview?project=158024523272 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.' },
  codePrefix: 'messaging' }

在那一系列错误之前,我收到了以下消息:

Successfully sent message: projects/project-ID/messages/8472962925969988574

我在做什么错?我该如何解决?再次获取成功发送的消息:(

谢谢大家的帮助。

0 个答案:

没有答案