user15322469
user15322469

Reputation: 909

how can i request message by using fcm api?

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

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

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

i have to use this url

which is

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

but i confused how can i use this url??

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

Upvotes: 0

Views: 1259

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599021

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.

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

Upvotes: 1

Related Questions