Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidRegistration when sending Firebase data messages with https://fcm.googleapis.com/fcm/send?

  1. I setup a REST client with POST --> https://fcm.googleapis.com/fcm/send
  2. Content-Type : application/json
  3. Authorization : key=<server-key>
  4. JSON Body:

    { "to": "testTopic", "data": { "key1" : "val1", "key2" : true } }

The repsonse in 200 OK but the response body has:

{
    "multicast_id": 6098503498585,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results":[
        {
        "error": "InvalidRegistration"
        }
    ]
}

So the onMessageReceived() is not triggered, neither app in foreground nor in background? Why do I get InvalidRegistration ? What am I missing?

The server key at point 3 is from Firebase Project settings --> Cloud messaging --> Server key

like image 392
Ralf Wickum Avatar asked Sep 11 '17 15:09

Ralf Wickum


People also ask

How do I send notifications to FCM using Firebase?

FCM can send a notification message including an optional data payload. In such cases, FCM handles displaying the notification payload, and the client app handles the data payload. For testing or for marketing and user re-engagement, you can send notification messages using the Firebase console .

Why Register Firebase Cloud Messaging?

Join us for Firebase Summit on November 10, 2021. Tune in to learn how Firebase can help you accelerate app development, release with confidence, and scale with ease. Register Firebase Cloud Messaging (FCM) offers a broad range of messaging options and capabilities.

How to use data messages in FCM?

Use data messages when you want to process the messages on your client app. FCM can send a notification message including an optional data payload. In such cases, FCM handles displaying the notification payload, and the client app handles the data payload.

How do I send custom key-value pairs to Firebase users?

FCM does not provide an end-to-end solution. However, there are external solutions available such as Capillary or DTLS. Both programmatically or via the Firebase console, you can send notification messages that contain an optional payload of custom key-value pairs. In the Notifications composer, use the Custom data fields in Advanced options.


1 Answers

In 4. your JSON requires a preceeding

/topics/

for "to" thus:

{ "to": "/topics/testTopic",....}
like image 112
Murat Ceven Avatar answered Sep 22 '22 04:09

Murat Ceven