Unsubscribe from a topic in FCM Web

I have successfully installed FCM on my website and it works fine. I use JavaScript to send notifications to the "movies" topic by subscribing to it.

fetch('https://iid.googleapis.com/iid/v1/'+tokenz+'/rel/topics/movies', { method: 'POST', headers: new Headers({ 'Authorization': 'key=****' }) 

I can not find the documentation to unsubscribe from a topic on the Internet using JS. What is the best way to unsubscribe from a single topic, and is there also a way to unsubscribe from all topics?

+5
source share
1 answer
Good question. It never occurred to me that there was no recommended way / guide to unsubscribe from FCM Web topics in the documentation .

As you already know, it is stated that in order to subscribe to a topic, you will need to use the instance identifier API . So I decided that you should use the same. I went through the documents, but there is no mention of what to use when unsubscribing one token from one / several topics (s).

For all that I would like to offer now, you should use batchRemove to unsubscribe from your topic token. 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. makes it invalid).

+4
source

Source: https://habr.com/ru/post/1265774/


All Articles