如何使用 SleekXMPP 或 python 处理 XMPP 订阅
这是我的用例:
- 用户单击网页上的链接说:“在 XMPP 上关注此人”
- 脚本启动并获取(基于注册数据)请求者的用户名和密码并启动。
- 订阅请求已发送。如果已发送订阅,则脚本不应发送另一订阅。如果订阅被拒绝,脚本应通知用户。
- 然后脚本应该退出
这是我到目前为止的代码,使用 SleekXMPP:
import sys, sleekxmpp, logging
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
#This is hardcoded here, for illustration.
jid = 'hermans@******.com/Work'
password = '********'
targetjid = 'simena@*******.com/Work'
class SubscribeWorker(sleekxmpp.ClientXMPP):
def __init__(self, jid, password):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.add_event_handler("session_start", self.start)
def start(self, event):
self.send_presence(pto=targetjid, ptype='subscribe')
self.get_roster()
if __name__ == '__main__':
logging.basicConfig(level=5,format='%(levelname)-8s %(message)s')
xmpp = SubscribeWorker(jid, password)
if xmpp.connect():
xmpp.process(threaded=False)
print("Done")
else:
print("Unable to connect.")
这成功发送了一个请求,但它不会占用任何现有请求或订阅状态的高度。有人有使用 XMPP 处理订阅/取消订阅的示例代码吗? 我试图理解维基和代码示例 - 我真的有,我只是现在被这段代码困住了。
预先感谢您的任何意见。
Here is my use-case:
- User clicks link on webpage saying: "Follow this person on XMPP"
- Script is initiated and gets (based on registered data) the requestors username and password and starts.
- The subscription request is sent. If a subscription is already sent, the script should not send another one. If the subscription was rejected, the script should notify the user.
- The script should then exit
Here is my code so far, using SleekXMPP:
import sys, sleekxmpp, logging
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
#This is hardcoded here, for illustration.
jid = 'hermans@******.com/Work'
password = '********'
targetjid = 'simena@*******.com/Work'
class SubscribeWorker(sleekxmpp.ClientXMPP):
def __init__(self, jid, password):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.add_event_handler("session_start", self.start)
def start(self, event):
self.send_presence(pto=targetjid, ptype='subscribe')
self.get_roster()
if __name__ == '__main__':
logging.basicConfig(level=5,format='%(levelname)-8s %(message)s')
xmpp = SubscribeWorker(jid, password)
if xmpp.connect():
xmpp.process(threaded=False)
print("Done")
else:
print("Unable to connect.")
This sends a request successfully, but it does not take height for any existing request or subscription status. Does anyone have example code on subscribe/unsubscribe handling with XMPP?
And I've tried to understand the wiki and code examples - I really have, I'm just stuck at the moment with this code.
Thanks in advance, for any input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者,尝试添加类似 xmpp:simena@<网页上的strong>*.com?subscribe,这应该在您现有的桌面客户端中执行正确的操作。
Alternately, try putting a like like xmpp:simena@*.com?subscribe on the web page, which should do the right thing in your existing desktop client.