Mahmoud Niypoo
Mahmoud Niypoo

Reputation: 1720

FCM unsubscribe specific token From Topic

I'm facing now issue that , I have FCM topic and this topic has many subscriber I want the admin removes user from topic not this user unsubscribe by him self.

Upvotes: 2

Views: 1899

Answers (2)

David Innocent
David Innocent

Reputation: 676

You can use firebase-admin. You just need to get the users' FCM tokens into an array then pass in the array of user tokens you would like to

// These registration tokens come from the client FCM SDKs.
var registrationTokens = [
  'YOUR_REGISTRATION_TOKEN_1',
  // ...
  'YOUR_REGISTRATION_TOKEN_n'
];

// Unsubscribe the devices corresponding to the registration tokens from
// the topic.
admin.messaging().unsubscribeFromTopic(registrationTokens, topic)
  .then(function(response) {
    // See the MessagingTopicManagementResponse reference documentation
    // for the contents of response.
    console.log('Successfully unsubscribed from topic:', response);
  })
  .catch(function(error) {
    console.log('Error unsubscribing from topic:', error);
  });

where the registrationTokens are the user tokens and topic is just String of the topic you would want to unscribe the user from.

check out firebase documentation below on the topic

Upvotes: 3

Frank van Puffelen
Frank van Puffelen

Reputation: 599856

If you have the (registration/instance ID) tokens of that user, you can use the Admin SDK to unsubscribe them. Note that using the Admin SDK must happen in a trusted environment, such as your development machine, a server you control, or Cloud Functions.

The API to unsubscribe tokens from topics is available in the Admin SDKs for Node.js, Java, Python, Go, and .NET.

Upvotes: 2

Related Questions