Mobile Push Notifications API for Python-Twisted SDK

Deprecated

NOTICE: Based on current web trends and our own usage data, PubNub's Python Twisted SDK is deprecated as of May 1, 2019. Deprecation means we will no longer be updating the Python Twisted SDK but will continue to support users currently using it. Please feel free to use our other Python SDK offerings as they will continue to be supported and maintained. If you would like to use the Python Twisted SDK specifically, we would love to work with you on keeping this project alive!

Mobile Push Notifications feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about Mobile Push Notifications.

Add a device to a push notifications channel​

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Enable mobile push notifications on a set of channels.

Method(s)​

Use the following method(s) in the Python-Twisted SDK:

1pubnub.add_channels_to_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
required
push_type required#
Type: PNPushType
Default: no default
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2.
channels required#
Type: List
Default: no default
Channels to enable for push notifications.
device_id required#
Type: String
Default: no default
Device token.
topic#
Type: String
Default: no default
APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2.
environment#
Type: String
Default: PNPushEnvironment.DEVELOPMENT
APNs environment. Required if push_type is PNPushType.APNS2.

Sample code​

Add device to channel​

1from pubnub.enums import PNPushType
2
3d = pubnub.add_channels_to_push()\
4 .push_type(PNPushType.GCM)\
5 .channels(["ch1", "ch2", "ch3"])\
6 .device_id("deviceId")\
7 .deferred()
8d.addCallback(my_callback)

Returns​

The add_channels_to_push() does not return actionable data. Check status.is_error() on the status object.

List push notifications channels for a device​

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

List channels that have push notifications enabled for the specified device token.

Method(s)​

Use the following method(s) in the Python-Twisted SDK:

1pubnub.list_push_channels().push_type(PNPushType).device_id(String).topic(String).environment(PNPushEnvironment)
required
push_type required#
Type: PNPushType
Default: no default
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2.
device_id required#
Type: String
Default: no default
Device token.
topic#
Type: String
Default: no default
APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2.
environment#
Type: String
Default: PNPushEnvironment.DEVELOPMENT
APNs environment. Required if push_type is PNPushType.APNS2.

Sample code​

List channels for device​

1from pubnub.enums import PNPushType
2
3d = pubnub.list_push_channels()\
4 .push_type(PNPushType.GCM)\
5 .device_id("deviceId")\
6 .deferred()
7d.addCallback(my_callback)

Returns​

The list_push_channels() operation returns a PNPushListProvisionsResult which contains the following fields:

Channels#
Type: List
List of channels associated for mobile push notifications.

Remove a device from push notifications channels​

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Disable mobile push notifications on a set of channels.

Method(s)​

Use the following method(s) in the Python-Twisted SDK:

1pubnub.remove_channels_from_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
required
push_type required#
Type: PNPushType
Default: no default
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2.
channels required#
Type: List
Default: no default
Channels to disable for push notifications.
device_id required#
Type: String
Default: no default
Device token.
topic#
Type: String
Default: no default
APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2.
environment#
Type: String
Default: PNPushEnvironment.DEVELOPMENT
APNs environment. Required if push_type is PNPushType.APNS2.

Sample code​

Remove device from channel​

1from pubnub.enums import PNPushType
2
3d = pubnub.remove_channels_from_push()\
4 .push_type(PNPushType.GCM)\
5 .channels("ch1", "ch2", "ch3")\
6 .device_id("deviceId")\
7 .deferred()
8d.addCallback(my_callback)

Returns​

The remove_channels_from_push() does not return actionable data. Check status.is_error() on the status object.

Was this page useful?

Last updated on