如何使用fcm api请求消息? [英] how can i request message by using fcm api?

查看:124
本文介绍了如何使用fcm api请求消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将本机与firebase一起使用,以使用fcm推送通知.

i'm using react native with firebase to use fcm push notification..

这是documnet示例

this is documnet example

            // 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请求消息

document says if i want to request message by using rest api instead of firebase admin

我必须使用此网址

这是

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

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

but i confused how can i use this url??

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

and i wonder should i use this url in backend or frontend?

推荐答案

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

Sending messages to devices through FCM requires that you specify the so-called FCM server key to the API. As its name implies this key should only be used in trusted environments, such as a server you control, your development machine, or Cloud Functions.

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

There is no secure way to send messages directly from client-side code directly through the FCM API. For more on this, see:

这篇关于如何使用fcm api请求消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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