Firebase FCM:无效参数 [英] Firebase FCM: invalid-argument

查看:170
本文介绍了Firebase FCM:无效参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试FCM,因此仅使用其示例代码.实际上,我什至在发送他们的示例消息.以下代码直接来自文档(除了来自其示例消息传递android工具的令牌),失败了:

I'm trying FCM for the first time, so just using their sample code. In fact I'm even sending their sample messages. The following code, which is straight from the documentation (except for the token which comes from their sample messaging android tool), fails:

exports.onBroadcastCreated =    functions.firestore.document('/apath    /...').onCreate(async event => {
   notification:{
  title:"Portugal vs. Denmark",
  body:"great match!"
},
token: 'eU2YUsi4Ugs:APA91bFH5bR9B1xosqrjvpw7HG4UkYTlDizmtra9pQRge-b4JxRbLjq9PVw91rqZytkUMKJXjPHd_dRlHHMk1bExCo_6Dxv99Vfp8MYz-H16Y9zmG8EFlWXNH4Tw_h6NRj2z1gLcz10m'
};

// Send a message to the device corresponding to the provided
// registration token.
return 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);
    console.log(message);
  });

}

如您所见,创建文档时,通知将从云功能发送.该函数称为确定",但日志显示如下:

So as you can see the notification would be sent from a cloud function when a document is created. The function is called OK, but the log shows this:

Error sending message: { Error: Request contains an invalid argument.
    at FirebaseMessagingError.Error (native)
    at FirebaseMessagingError.FirebaseError [as constructor] (/user_code   /node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
    at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
    at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:149:50
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
  errorInfo: 
   { code: 'messaging/invalid-argument',
     message: 'Request contains an invalid argument.' },
  codePrefix: 'messaging' }

{ notification: { title: 'Portugal vs. Denmark', body: 'great match!' },
  token: 'eU2YUsi4Ugs:APA91bFH5bR9B1xosqrjvpw7HG4UkYTlDizmtra9pQRge-b4JxRbLjq9PVw91rqZytkUMKJXjPHd_dRlHHMk1bExCo_6Dxv99Vfp8MYz-H16Y9zmG8EFlWXNH4Tw_h6NRj2z1gLcz10m' }

推荐答案

正如Carlos Fernandez Sanz指出的,其原因之一是客户端和服务器连接到了不同的Firebase项目.项目名称显示在客户端上的google-services.json文件中以及服务器上的凭据json中.

As Carlos Fernandez Sanz pointed out, one cause for this is that the client and server are connected to different firebase projects. Project name appears in the google-services.json file on the client and in the credentials json on the server.

这篇关于Firebase FCM:无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆