【问题标题】:Unable to send FCM Message using Cloud Functions for Firebase无法使用 Cloud Functions for Firebase 发送 FCM 消息
【发布时间】:2017-05-09 18:09:01
【问题描述】:

我正在尝试发送使用 Cloud Functions for Firebase 发送 FCM 消息的基本用例。该功能超时,消息从未发送。这是函数。

exports.sendNotification = functions.https.onRequest((req, res) => {
    const keyword = req.query.keyword;
    const username = req.query.username;

    var payload = {
        data: {
            SearchKeyword: keyword,
            user: username
        }
    };

    const token = "real_fcm_token";

    return admin.messaging().sendToDevice(token, payload);


});

如何更新上述代码块才能向设备发送数据消息?

【问题讨论】:

    标签: firebase firebase-cloud-messaging google-cloud-functions


    【解决方案1】:

    除了从sendToDevice() 返回Promise,您还必须返回send HTTP status。例如:

    res.status(200).send('Success');
    
    const token = "real_fcm_token";
    
    return admin.messaging().sendToDevice(token, payload);
    

    【讨论】:

    • 谢谢,解决了超时问题,但由于某种原因,FCM 消息仍然没有发送。
    • @ValOkafor: sendToDevice() 在承诺中返回 MessagingDevicesResponse。您可以从中获取成功/失败状态:example code here.
    猜你喜欢
    • 1970-01-01
    • 2018-11-04
    • 2017-09-09
    • 2018-01-15
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 2017-11-10
    相关资源
    最近更新 更多