Banning and Muting Users
PubNub Access Manager enables you to manage access controls for individual users so they can be muted and banned on specific channels. It's important to be able to ban users if they're sharing inappropriate content or are violating other terms of use defined on your application.
Ban user in channels
To ban a user in channels, call the grant method and set the read and write permissions on the channels to false.
pubnub.grant({
channels: ['ch-1','ch-2'], //channels to allow grant on
authKeys: ['key1'], // the keys we are provisioning
read: false,
write: false,
}, (status) => {
// handle status
});
pubnub.grant()
.channels(Arrays.asList("ch-1")) //channels to allow grant on
.authKeys(Arrays.asList("key1")) // the keys we are provisioning
.write(false) // allow those keys to write (false by default)
.read(false) // allow keys to read the subscribe feed (false by default)
.async(new PNCallback<PNAccessManagerGrantResult>() {
@Override
public void onResponse(PNAccessManagerGrantResult result, PNStatus status) {
// PNAccessManagerGrantResult is a parsed and abstracted response from server
}
});
pubnub.Grant()
.Channels(new string[]{
"ch-1"
})
.AuthKeys(new string[] {
"key1"
})
.Write(false) // allow those keys to write (false by default)
.Read(false) // allow keys to read the subscribe feed (false by default)
.Execute(new PNAccessManagerGrantResultExt(
(result, status) => {
// PNAccessManagerGrantResult is a parsed and abstracted response from server
}
));
res, status, err := pn.Grant().
Channels([]string{"ch-1"}). // channels to allow grant on
AuthKeys([]string{"key1"}). // the keys we are provisioning
Read(false). // allow those keys to write (false by default)
Write(false). // allow those keys to manage channel groups (false by default)
Execute()
fmt.Println(res, status, err)
Mute user in channels
To mute a user in channels, call the grant method and set the write permissions on the channels to false.
pubnub.grant({
channels: ['ch-1','ch-2'], //channels to allow grant on
authKeys: ['key1'], // the keys we are provisioning
write: false,
}, (status) => {
// handle status
});
pubnub.grant()
.channels(Arrays.asList("ch-1")) //channels to allow grant on
.authKeys(Arrays.asList("key1")) // the keys we are provisioning
.write(false) // allow those keys to write (false by default)
.async(new PNCallback<PNAccessManagerGrantResult>() {
@Override
public void onResponse(PNAccessManagerGrantResult result, PNStatus status) {
// PNAccessManagerGrantResult is a parsed and abstracted response from server
}
});
pubnub.Grant()
.Channels(new string[]{
"ch-1"
})
.AuthKeys(new string[] {
"key1"
})
.Write(false) // allow those keys to write (false by default)
.Execute(new PNAccessManagerGrantResultExt(
(result, status) => {
// PNAccessManagerGrantResult is a parsed and abstracted response from server
}
));
res, status, err := pn.Grant().
Channels([]string{"ch-1"}). // channels to allow grant on
AuthKeys([]string{"key1"}). // the keys we are provisioning
Write(false). // allow those keys to manage channel groups (false by default)
Execute()
fmt.Println(res, status, err)