0

https://firebase.google.com/docs/cloud-messaging/unity/upstream?hl=ko

I am following the next page. I can't use Send. What should I do?

Firebase.Messaging.Message message;
message.To = SENDER_ID + "@fcm.googleapis.com";
message.MessageId = get_unique_message_id();
message.Data("my_message", "Hello World");
message.Data("my_action", "SAY HELLO");
message.TimeToLive = kTimetoLive;
Firebase.Messaging.FirebaseMessaging.Send(message);

When I asked ChatGPT, they told me to use SendAsync, but there is no such command. So I'm trying to send it by Post, but it's not easy. It looks like I need to be authenticated, but no matter how much I look at the documentation, I'm not familiar with the implementation of Google Authentication.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Roy
  • 13
  • 3

1 Answers1

0

Sending upstream messages through FCM is exceedingly uncommon these days, and the wish to use it is mostly based on misunderstanding what it does. Sending an upstream message through XMPP delivers that message to your app server that listens for those messages. Is is not a way to send a message from one device to another device.

Sending a message to a device must always be done from a trusted environment, such as your development machine, a server that you control, or something like Cloud Functions/Cloud Run.

For more on this, also check out: How to send one to one message using Firebase Messaging

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you for your kind reply. I'm also looking into Firebase Functions, but it seems to be lacking a lot of documentation or examples for Unity users. Maybe it's because there are no people using it... I don't know if I can implement it. – Roy May 13 '23 at 04:56
  • First off: do the first paragraphs of my answer makes sense, and explain why your current approach won't work? If so: Also see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) --- Cloud Functions for Firebase are written in Node.js, so there's no need for Unity example. But there are many other options too, as long as you run the code to send the message on a trusted environment. I.e. it can be as simple as running a CURL command in a terminal: https://stackoverflow.com/a/37376757 – Frank van Puffelen May 13 '23 at 14:10
  • Thank you for taking your valuable time to answer. But I don't know how to bridge the gap between Firebase Messaging and Function. Send upstream messages with Messaging. I can understand. However, the sending order has disappeared. (Why did they get rid of this?) Then it just stops at whether it should be sent in the Post method. (Why wasn't the document updated?) At the end of the twists and turns, I got past the start of Function, but the problem seems to be that I don't know how to connect the two. After spending a few days in a daze, I am grateful that someone answered me. – Roy May 13 '23 at 15:37
  • We can discuss why sending upstream messages through XMPP is uncommon enough that it didn't warrant maintaining it, but the most important thing here is that it wouldn't have done what you need anyway. There has never been an API to send messages from one device to another in Firebase Cloud Messaging. Sending (so called downstream) messages to a device **always** had to be done from a trusted environment. The `curl` call in the example I linked in my last comment is a simple example of how to do that, so I recommend giving it a try. – Frank van Puffelen May 13 '23 at 16:02