【问题标题】:how can i request message by using fcm api?如何使用 fcm api 请求消息?
【发布时间】:2021-06-23 06:32:51
【问题描述】:

我正在使用 react native 和 firebase 来使用 fcm 推送通知..

这是文档网络示例

            // Node.js
            var admin = require('firebase-admin');

            // ownerId - who owns the picture someone liked
            // userId - id of the user who liked the picture
            // picture - metadata about the picture

            async function onUserPictureLiked(ownerId, userId, picture) {
            // Get the owners details
            const owner = admin
                .firestore()
                .collection('users')
                .doc(ownerId)
                .get();

            // Get the users details
            const user = admin
                .firestore()
                .collection('users')
                .doc(userId)
                .get();

            await admin.messaging().sendToDevice(
                owner.tokens, // ['token_1', 'token_2', ...]
                {
                data: {
                    owner: JSON.stringify(owner),
                    user: JSON.stringify(user),
                    picture: JSON.stringify(picture),
                },
                },
                {
                // Required for background/quit data-only messages on iOS
                contentAvailable: true,
                // Required for background/quit data-only messages on Android
                priority: 'high',
                },
            );
            }

文档说如果我想通过使用 rest api 而不是 firebase admin 来请求消息

我必须使用这个网址

这是

          https://fcm.googleapis.com/fcm/send

但我很困惑如何使用这个网址??

我想知道我应该在后端还是前端使用这个网址?

【问题讨论】:

    标签: node.js reactjs firebase react-native firebase-cloud-messaging


    【解决方案1】:

    通过 FCM 向设备发送消息需要您为 API 指定所谓的 FCM 服务器密钥。顾名思义,此密钥只能在受信任的环境中使用,例如您控制的服务器、您的开发机器或 Cloud Functions。

    没有直接通过 FCM API 从客户端代码直接发送消息的安全方法。有关这方面的更多信息,请参阅:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多