javascript - TypeError : admin. messages.sendToDevice 不是一个函数,使用 firebase 函数

标签 javascript firebase google-cloud-firestore google-cloud-functions firebase-cloud-messaging

在使用以下函数时,我正在向设备发送通知,我在用于消息传递的 firebase 云函数中收到此错误

TypeError: admin.messaging.sendToDevice is not a function

return admin.messaging.sendToDevice(to_token_id,payload).then(result=>{

            console.log("Notification Sent Successful");
            return null;
        });

上述方法是否已被弃用? 如果是这样,那么新的是什么? 上面的firebase云函数是用javascript编写的。

最佳答案

sendToDevice,需要使用send()方法:

// The topic name can be optionally prefixed with "/topics/".
var topic = 'highScores';

var message = {
  data: {
    score: '850',
    time: '2:45'
  },
  topic: topic
};

// Send a message to devices subscribed to the provided topic.
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);
  });

https://firebase.google.com/docs/cloud-messaging/android/send-multiple#build_send_requests

关于javascript - TypeError : admin. messages.sendToDevice 不是一个函数,使用 firebase 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60987569/

相关文章:

javascript - 使用 JQuery 提交表单

android - 弹出的 React Native 应用程序无法到达 Firestore 后端

firebase - 为要存储的每个操作创建新客户端?

java - 如何从 Firestore 中检索 float ?

javascript - Firebase 错误 - 提供给 Query.startAt() 的参数过多

firebase - Firestore 数据建模文章和类别

javascript - jQuery "curtain"函数 - 最佳解决方案?

javascript - 使用 Javascript 将 DIV 高度设置为 100% 导致跨浏览器问题

javascript - 如何使用 TINYMCE images_upload_handler 发送其他 POST 数据

android - FirebaseAuthUserCollisionException?