繁体   English   中英

如何解决{错误:'MismatchSenderId'}?

[英]How to solve { error: 'MismatchSenderId' }?

我想做的是使用 Expo 服务器进行推送通知。 我也遵循了前端和后端的 expo 文档。 https://docs.expo.dev/push-notifications/overview/ I don't have any experience with push notifications, but by far all I know is that the Expo server can take care of handling the expo token notifications, but all I have to do is just to make some configuration with the firebase to my project: https://docs.expo.dev/push-notifications/using-fcm/ Also I have run expo push:android:upload --api-key ,哪个令牌是我从 Firebase 中获得的服务器密钥

创建 APK 后,我的 Heroku 日志(部署我的项目后端的位置)向我显示此错误:

 chunk [
   {
     to: 'ExponentPushToken[xxxxxxxxxxxxxxxxxx]',
     sound: 'default',
     body: 'MyApp',
     data: { withSome: 'data' }
   }
 ]
 ticket chunk [
   {
     id: '37153ff5-a52b-4a36-8973-b3845211d8f9',
     status: 'error',
     message: "There was an unknown error with the FCM server. See this error's details for more information.",
     messageEnum: 16,
     details: {
       error: 'ProviderError',
       errorCodeEnum: 1,
       fault: 'fcm',
       fcm: [Object]
     }
   }
 ]
 ticket Chunk fcm object access: { error: 'MismatchSenderId' }

后端:

exports.pushNotification = asyncHandler(async (req, res, next) => {
  const { somePushTokens } = req.body;
  let allToken = [];

  for (let i in somePushTokens) {
    allToken.push(somePushTokens[i].token);
  }

  let expo = new Expo({
    accessToken: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
  });

  let messages = [];
  for (let pushToken of allToken) {
    if (!Expo.isExpoPushToken(pushToken)) {
      console.error(`Push token ${pushToken} is not a valid Expo push token`);
      continue;
    }
    messages.push({
      to: pushToken,
      sound: "default",
      body: "MyApp",
      data: { withSome: "data" },
    });
  }

  let chunks = expo.chunkPushNotifications(messages);
  console.log("chunks", chunks);
  let tickets = [];
  (async () => {
    for (let chunk of chunks) {
      console.log("chunk", chunk);
      try {
        let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
        console.log("ticket chunk", ticketChunk);
        console.log("ticket Chunk fcm object access:", ticketChunk[0].details.fcm);
        tickets.push(...ticketChunk);
      } catch (error) {
        console.error("Error ticket chunk", error);
      }
    }
  })();

  let receiptIds = [];
  for (let ticket of tickets) {
    if (ticket.id) {
      receiptIds.push(ticket.id);
    }
  }

  let receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
  (async () => {
    for (let chunk of receiptIdChunks) {
      try {
        let receipts = await expo.sendPushNotificationsAsync(chunk);
        console.log("recipts: ", receipts);

        for (let receiptId in receipts) {
          let { status, message, details } = receipts[receiptId];
          if (status === "ok") {
            continue;
          } else if (status === "error") {
            console.error(
              `There was an error sending a notification: ${message}`
            );
            console.error(`The error code in status is:  ${details.error}`);
            console.error(`The error fcm in status is":  ${details.fcm}`);
            if (details && details.error && details.fcm) {
              console.error(`The error code is:  ${details.error}`);
              console.error(`The error fcm is":  ${details.fcm}`);
            }
          }
        }
      } catch (error) {
        console.error("The error: ", error);
      }
    }
  })();

  res.status(200).json({
    success: true,
    data: messages,
    msg: "Notification has been send",
  });
});

我该如何解决这个错误?

MismatchSenderId 表示您的客户端正在注册与您用于发送的服务器不同的服务器

请参阅此文档: https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM