Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging InvalidRegistration for Topic Messages

I am having trouble sending a topic downstream message using Firebase. Everything works fine when I send to single or multiples users using tokens, my code looks like this

notif = {
    'to': 'TOKEN',
    'data': {'msg': 'whatever'},
}
opener = urllib2.build_opener()
data = json.dumps(notif)
req = urllib2.Request(
    FCM_URL,
    data=data,
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'key=' + API_KEY,
    }
)
response = opener.open(req)

However if I replace the recipients using a topic, more precisely the code becomes

notif = {
    'to': '/topic/MY_TOPIC',
    'data': {'msg': 'whatever'},
}
opener = urllib2.build_opener()
data = json.dumps(notif)
req = urllib2.Request(
    FCM_URL,
    data=data,
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'key=' + API_KEY,
    }
)
response = opener.open(req)

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

Is there something I am missing? I should outline that sending topic messages from the firebase console works fine.

Any help more than welcome, Best & thanks! Alex

like image 249
Al Wld Avatar asked Mar 13 '26 19:03

Al Wld


1 Answers

Ah so silly...

I was missing s in topics, the correct form is hence

notif = {
'to': '/topics/MY_TOPIC',
'data': {'msg': 'whatever'},
}

Hope it helps someone anyway!

Best, A

like image 175
Al Wld Avatar answered Mar 15 '26 09:03

Al Wld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!