简体   繁体   中英

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

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

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