简体   繁体   中英

Push notifications error “Missing registration” firebase functions

Im trying to send push notifications from my firebase functions and i get this error "Error=MissingRegistration"

i tried using postman and it works perfectly, but when firebase run my js function it doesnt work.

This is my JavaScript Code:

 var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; var xhttp = new XMLHttpRequest(); xhttp.open("POST", "https://fcm.googleapis.com/fcm/send", true); xhttp.setRequestHeader("Content-type", "application/json"); xhttp.setRequestHeader("Authorization", "key="+key); let res = {'notification': { 'title': 'Test', 'body': 'Notificación enviada desde Firebase' }, 'to':token, } xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { console.log(xhttp.responseText) } }; xhttp.send(JSON.stringify(res))

According to Firebase documentation error:MissingRegistration is returned when you have a Missing Registration Token

I would recommend that you check if token value is what you expected and not null, in the cloud function

let res = {'notification': {
                'title': 'Test',
                'body': 'Notificación enviada desde Firebase'
            },

            'to':token,

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM