PubNub Facebook通知
这是一个类似于Facebook的窗口框的示例,该窗口框通过PubNub通知您的用户自定义消息。您可以在用户的手机或浏览器上向他们发送更新。这将向您的用户显示通知;任何通知您。
使用PubNub允许通过的WebSockets,波什,彗星和其他机制在你的应用程序中使用您提供发送数据的能力数据推 在任何时间 直接通过您的用户
MASS广播 或 个别通知 。
从这里开始:现场演示
立即尝试: http : //pubnub-demo.s3.amazonaws.com/facebook-
notification/index.html下载源代码: https
:
//github.com/pubnub/javascript/tree/master/examples/facebook-
notification
从这里开始,轻松复制/粘贴代码。入门非常容易,我们建议您在开始之前先使用上面的示例链接。
设置页面
首先包括 FBootstrap 资源,以提供通知窗口的外观。将这些样式添加到您的HTML文件。
<link href=bootstrap.css rel=stylesheet><style type=text/css> body { padding-top: 60px; } </style>数据连接码
接下来,您需要设置一个PubNub数据连接,然后为接收到的数据添加处理规则。
<script src="https://pubnub.s3.amazonaws.com/pubnub-3.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-modal/2.2.6/js/bootstrap-modal.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script>(function(){ // PubNub (For Data Push to User) var pubnub = PUBNUB.init({ subscribe_key : 'demo', ssl: false }); // Setup New Data Push Connectoin via PubNub pubnub.subscribe({ restore : true, channel : 'example-user-id-1234', callback : show_notification }); // Setup alert Window $('#new-alert').modal({ keyboard : true }); // Show the Notification Window function show_notification(message) { $('#new-alert').modal('show'); } // Simulate Notification $('#simulate-notification').bind( 'mousedown', function() { pubnub.publish({ channel : 'example-user-id-1234', message : 'alert' }); return false; } ); })();</script>Python Push范例
接下来,您需要将此
python代码添加到 Django 或任何其他框架中。您可以将此添加到
messagepost应用程序的代码中。这会将通知发布给您的用户。此特定示例将使通知显示在Facebook Notification页面中。
pip install pubnub
Python源
## PubNub Setupimport pubnub from Pubnubpubnub = Pubnub( 'demo', 'demo', None, False )## Push Notice to 'example-user-id-1234'info = pubnub.publish({ 'channel' : 'example-user-id-1234', 'message' : { 'your-data' : 'any-data-here' }})print(info)


