消息有效负载包含无效的"android"财产.有效属性是“数据".和“通知" [英] Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification"

查看:126
本文介绍了消息有效负载包含无效的"android"财产.有效属性是“数据".和“通知"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用特定于平台的配置通过Firebase Cloud Functions发送推送通知.我从 https://firebase.google.com/docs/cloud-消息/发送消息

I'm trying to send Push Notifications with Firebase Cloud Functions with platform specific configuration. I got following config from https://firebase.google.com/docs/cloud-messaging/send-message

var message = {
  notification: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  data: {
    channel_id: threadId,
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  },
  apns: {
    payload: {
      aps: {
        badge: 42,
      },
    },
  },
};

但出现admin.messaging().sendToDevice(deviceToken, message)

Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification"

任何主意这里有什么问题吗?还是一些适用于iOS/Android平台的正确配置示例?

Any idea what is wrong here? Or maybe some samples of proper configuration for iOS/Android platforms?

推荐答案

sendToDevice()是使用旧版FCM HTTP端点的函数.传统端点不提供特定于平台的字段.为了获得该功能,可以通过send()函数使用新的端点.您可能需要更新您的Admin SDK版本.您可以在此处的文档中查看示例.

sendToDevice() is a function that uses the legacy FCM HTTP endpoint. The legacy endpoint doesn't offer platform-specific fields. In order to get that functionality, you can use the new endpoint through the send() function. You may need to update your version of the Admin SDK. You can see an example in the documentation here.

例如,对于您提供的代码,您将发送如下消息:

For the code you provided, for example, you would send a message like this:

let message = {
  notification: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  data: {
    channel_id: threadId,
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  },
  apns: {
    payload: {
      aps: {
        badge: 42,
      },
    },
  },
  token: deviceToken,
};

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);
  });

请注意,设备令牌现在位于message对象中.

Notice the device token is now in the message object.

这篇关于消息有效负载包含无效的"android"财产.有效属性是“数据".和“通知"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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