Error missingregistration firebase

I have seen this topic discussed before, but I think it's not the same scenario. I'm trying to send push notification from one device (going to be an admin device) through FCM (Firebase Cloud Mess...

I have seen this topic discussed before, but I think it’s not the same scenario.

I’m trying to send push notification from one device (going to be an admin device) through FCM (Firebase Cloud Messaging) to all other devices, and i’m going exactly by their docs.

I have tried to subscribe to topics or keep it simple still getting the same error:

MissingRegistration

 String jsonData = "{"to":"/topics/news","notification":{"title":"title","body":"text" }}";
                byte[] postData = jsonData.getBytes(Charset.forName("UTF-8"));
                int postDataLength = postData.length;

                URL url = new URL("https://fcm.googleapis.com/fcm/send");
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setDoInput(true);
                con.setDoOutput(true);
                con.setInstanceFollowRedirects(true);
                con.setRequestMethod("POST");

                con.setRequestProperty("Content-Type","application/json");
                con.setRequestProperty("Authorization","key=AIzaSyB70J***-z34q2_h*******qjZsM5zBIf8Y"); //I've added stars :-) 
                con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
                con.setRequestProperty("Content-Type","charset=UTF-8");
                con.setRequestProperty("Content-Length",Integer.toString(postDataLength));

                con.setUseCaches(false);

                DataOutputStream wr = new DataOutputStream(con.getOutputStream());
                wr.write(postData);

                InputStream inputStream= con.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                String outPut = "";
                while (((line = reader.readLine()) != null)){
                    outPut += line;
                }

Randika Vishman's user avatar

asked Aug 7, 2016 at 12:35

XcodeNOOB's user avatar

I was using/trying to send FCM Push notification using Postman web API Client app, to FCM URL: https://fcm.googleapis.com/fcm/send

And I had used a wrong Content-Type: application/x-www-form-urlencoded, So I changed it to

Content-Type:  application/json

This is basically required, as we are sending the Push Notification as a JSON Payload.

Cheers!

answered May 21, 2018 at 5:33

Randika Vishman's user avatar

Randika VishmanRandika Vishman

7,9133 gold badges58 silver badges80 bronze badges

1

I also got the same error, but mine was on the server side(push from rails to android), but my problem was that i had forgot to specify the content type in the header(i am using RestClient to post to firebase). Hope it might help someone

RestClient.post( "https://fcm.googleapis.com/fcm/send",
             {:to => reg_id,:notification => options }.to_json,{:content_type => :json, :accept => :json,:Authorization => "key=*****"}

answered Aug 13, 2016 at 7:28

Leo Much's user avatar

Leo MuchLeo Much

5994 silver badges6 bronze badges

Thank you for posting your answer,
anyway my codes works now,
all I had to do is change the content-type (I have just copied from firebase docs the content-types )and send it to a subscribe topic….
now all my users can get the notification from my device :-).

answered Aug 14, 2016 at 8:52

XcodeNOOB's user avatar

XcodeNOOBXcodeNOOB

2,1154 gold badges23 silver badges28 bronze badges

Android Question Firebase FCM Missing Registration Error

  • Thread starter
    VictorTandil

  • Start date
    Jun 23, 2017

  • Similar Threads
    Similar Threads

VictorTandil


  • #1

Good morning. I have two questions about the FCM service.

1) What is the line of code that registers the user on the FCM server?

Would it be next?

In that case, every time the App goes to «Resume» should I initialize it again?

On some occasions (not always) I get the error when sending a message that says «MissingRegistration».

2) Does the API_KEY change from time to time?

Approximately every two weeks, the key in the console changes without warning, which blocks users to send messages. This is normal?

DonManfred


  • #2

Based on the Firebase tutorial this line is in the firebaseMessaging service which, itself, is started from the starter service.
So, you dont need to do anything more than to start your app. Everytime you start the app, a token will be aquired. It may be the same token for days/weeks.
But it can happen that it changes! There is a event for this…

So, in your subscribetotopics you can call a server app on your server to give the token to your server. The server itself stores the token in a database or whatever.

Use the values stored in your server to send pushes.

741 votes

0 answers

Get the solution ↓↓↓

index.html

<html>
<title>Firebase Messaging Demo</title>
<style>
    div {
        margin-bottom: 15px;
    }
</style>
<body>
    <div id="token"></div>
    <div id="msg"></div>
    <div id="notis"></div>
    <div id="err"></div>
    <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-messaging.js"></script>
    <!-- For an optimal experience using Cloud Messaging, also add the Firebase SDK for Analytics. -->
    <script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-analytics.js"></script>
    <script>
        MsgElem = document.getElementById("msg");
        TokenElem = document.getElementById("token");
        NotisElem = document.getElementById("notis");
        ErrElem = document.getElementById("err");
        // Initialize Firebase
        // TODO: Replace with your project's customized code snippet
        var config = {
            apiKey: "AIzaSyCi6tjFP-VV71i__mHWgAN3uHkV3QXpPQv",
            authDomain: "my-app-3ab21.firebaseapp.com",
            databaseURL: "https://my-app-3ab21.firebaseio.com",
            projectId: "my-app-3ab21",
            storageBucket: "my-app-3ab21.appspot.com",
            messagingSenderId: "368038679727",
            appId: "1:368038679725:web:fb79116bcac4c6894be225"
        };

        firebase.initializeApp(config);

        const messaging = firebase.messaging();
        messaging
            .requestPermission()
            .then(function () {
                MsgElem.innerHTML = "Notification permission granted." 
                console.log("Notification permission granted.");
                
                // get the token in the form of promise
                return messaging.getToken()
            })
            .then(function(token) {
                TokenElem.innerHTML = "token is : " + token
            })
            .catch(function (err) {
                ErrElem.innerHTML =  ErrElem.innerHTML + "; " + err
                console.log("Unable to get permission to notify.", err);
            });

        messaging.onMessage(function(payload) {
            console.log("Message received. ", payload);
            NotisElem.innerHTML = NotisElem.innerHTML + JSON.stringify(payload);
            //kenng - foreground notifications
            const {title, ...options} = payload.notification;
            navigator.serviceWorker.ready.then(registration => {
                registration.showNotification(title, options);
            });
        });
    </script>
    </body>
</html>

curl-test(shell script)

curl -X POST -H "Authorization: key=AAAAVbDQlK0:APA91bGz7rxEi96dfTvCaHoqx0za_mNZzLEuqdebRuJ_h2Cv1zbuKqkBJvXaCA5nuBiSmiYqQX0p6sUqZIbT_x9mgDf_0MrTg2fYeG0ecng5dmygJVckdYp_fha969Rfn4jTQ7G30yJx" -H "Content-Type: application/json" 
   -d '{
  "data": {
    "notification": {
        "title": "FCM Message",
        "body": "This is an FCM Message",
        "icon": "/itwonders-web-logo.png",
    }
  },
  "to": "<DEVICE_REGISTRATION_TOKEN>"
}' https://fcm.googleapis.com/fcm/send

I am create a web application push notification using FCM when I run it then ask me toallow or block notification and when I allow notification then it show token and a messageNotification permission granted. but when I try to push notification to get message ofcurl file throughPostman then it through an error i.e.Error=MissingRegistration.

enter image description here

So, How can I fix this? Please help me.

Thank You

2021-11-23


Share solution ↓

Additional Information:

Date the issue was resolved:

2021-11-23

Link To Source

Link To Answer
People are also looking for solutions of the problem: can’t write image data to path

Didn’t find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.


Similar questions

Find the answer in similar questions on our website.

For Firebase, You can get info from https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes

Check that the request contains a registration token (in the
registration_id in a plain text message, or in the to or
registration_ids field in JSON).

For the new cloud Message, when you want to send a dwonstream message from the server, you need to use «to» to declaim the target registration id.

like below :

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."
}

You probably forgot to specify the content type in the header to be JSON.

Content-Type: application/json

If Content-Type is omitted, the format is assumed to be plain text.

And for plain text the registration ID is passed in a parameter called registration_id instead of registration_ids, which explains your MissingRegistration error.

Tags:

Json

Android

Push Notification

Google Cloud Messaging

Related

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error missing server jvm at minecraft
  • Error missing server jvm at c java bin server jvm dll
  • Error missing semicolon semi
  • Error missing return statement mypy
  • Error missing return statement java

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии