FCM 从主题中取消订阅特定令牌
FCM unsubscribe specific token From Topic
我现在面临的问题是,我有 FCM 主题并且这个主题有很多订阅者我希望管理员从主题中删除用户而不是这个用户自己退订。
如果您拥有该用户的(registration/instance ID)令牌,则可以use the Admin SDK to unsubscribe them。请注意,使用 Admin SDK 必须在受信任的环境中进行,例如您的开发机器、您控制的服务器或 Cloud Functions。
用于从主题取消订阅令牌的 API 在 Node.js, Java, Python, Go, and .NET 的 Admin SDK 中可用。
您可以使用 firebase-admin。你只需要将用户的 fcm 令牌放入一个数组中,然后传入你想要的用户令牌数组
// 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);
});
其中 registrationTokens 是用户令牌,topic 只是您希望取消用户订阅的主题的字符串。
查看 firebase documentation below on the topi
希望对您有所帮助。如果您仍然卡住,请告诉我。
我现在面临的问题是,我有 FCM 主题并且这个主题有很多订阅者我希望管理员从主题中删除用户而不是这个用户自己退订。
如果您拥有该用户的(registration/instance ID)令牌,则可以use the Admin SDK to unsubscribe them。请注意,使用 Admin SDK 必须在受信任的环境中进行,例如您的开发机器、您控制的服务器或 Cloud Functions。
用于从主题取消订阅令牌的 API 在 Node.js, Java, Python, Go, and .NET 的 Admin SDK 中可用。
您可以使用 firebase-admin。你只需要将用户的 fcm 令牌放入一个数组中,然后传入你想要的用户令牌数组
// 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);
});
其中 registrationTokens 是用户令牌,topic 只是您希望取消用户订阅的主题的字符串。
查看 firebase documentation below on the topi
希望对您有所帮助。如果您仍然卡住,请告诉我。