I successfully set FCM in my Website and it is working perfectly. I am using JavaScript to send notification to a 'movies' topic by subscribing it.
fetch('https://iid.googleapis.com/iid/v1/'+tokenz+'/rel/topics/movies', {
method: 'POST',
headers: new Headers({
'Authorization': 'key=****'
})
I don't find any documentation to unsubscribe a topic in web using JS. What is the best way to unsubscribe a single topic and also is there a way to unsubscribe to all topics?
Good question. It never really hit me that there wasn't an advised way/guide to unsubscribe from topics for FCM Web in the documentation.
As you already know, it is stated that in order to subscribe to a topic, you'll have to make use of the Instance ID API. So I figured that you should use the same. I've gone through the docs, but there isn't anything mentioned which to use when unsubscribing a single token from a single/multiple topic(s).
With all that said, what I would suggest for now is to use batchRemove
to unsubscribe your specific token from a topic. Example from the docs:
https://iid.googleapis.com/iid/v1:batchRemove
Content-Type:application/json
Authorization:key=API_KEY
{
"to": "/topics/<YOUR TOPIC NAME HERE>",
"registration_tokens": ["<YOUR TOKEN HERE>"]
}
I also tried the DELETE API, but it deletes the registration token itself (i.e. invalidates it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With