Facebook:如何使用xmpp作为fanpage发送私人消息

2024-10-04 05:22:32 发布

您现在位置:Python中文网/ 问答频道 /正文

几天后,我决定寻求解决问题的办法。在

我正在尝试使用XMPP协议和python向facebook用户发送一条私人消息作为我的粉丝页面。在

我使用下面的代码创建客户端:

import sleekxmpp

class SendMsgBot(sleekxmpp.ClientXMPP):
    def __init__(self, jid, recipient, message):
        sleekxmpp.ClientXMPP.__init__(self, jid, 'ignore')
        self.recipient = recipient
        self.msg = message
        self.add_event_handler("session_start", self.start, threaded=True)

    def start(self, event):
        self.send_presence()
        self.get_roster()
        self.send_message(mto=self.recipient,
        mbody=self.msg,
        mtype='chat')
        self.disconnect(wait=True)

这是我使用上面创建的客户端发送消息的代码:

^{pr2}$

在上面的代码中使用我的facebook登录名和密码,我没有得到任何错误。但我需要用我的粉丝页面发送信息。在

我成功地用我的api密钥和访问令牌进行了身份验证,但控制台冻结了一段时间,并显示以下消息:

DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: auth_success
DEBUG:sleekxmpp.xmlstream.xmlstream:SEND (IMMED): <stream:stream to='chat.facebook.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <stream:stream version="1.0" from="chat.facebook.com" id="1" xml:lang="en">
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <stream:features xmlns="http://etherx.jabber.org/streams"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" /><session xmlns="urn:ietf:params:xml:ns:xmpp-session" /></stream:features>
DEBUG:sleekxmpp.features.feature_bind.bind:Requesting resource: 
DEBUG:sleekxmpp.xmlstream.xmlstream:SEND (IMMED): <iq type="set" id="6e6fe59f-1683-41a9-9a32-dc8a952cdecd-2"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" /></iq>
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <iq type="result" from="-100002126842229@chat.facebook.com" id="6e6fe59f-1683-41a9-9a32-dc8a952cdecd-2"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>-100002126842229@chat.facebook.com/xymAXUKM</jid></bind></iq>

暂停之后,我收到了另一条消息:

WARNING:sleekxmpp.xmlstream.handler.waiter:Timed out waiting for IqWait_6e6fe59f-1683-41a9-9a32-dc8a952cdecd-2
ERROR:sleekxmpp.xmlstream.xmlstream:Error processing stream handler: Stream Features
Traceback (most recent call last):
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 1669, in _event_runner
    handler.run(args[0])
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/xmlstream/handler/callback.py", line 76, in run
    self._pointer(payload)
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/clientxmpp.py", line 280, in _handle_stream_features
    if handler(features) and restart:
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/features/feature_bind/bind.py", line 50, in _handle_bind_resource
    response = iq.send(now=True)
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/stanza/iq.py", line 230, in send
    raise IqTimeout(self)
IqTimeout
ERROR:sleekxmpp.xmlstream.stanzabase:Error handling {jabber:client}features stanza
Traceback (most recent call last):
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/xmlstream/xmlstream.py", line 1669, in _event_runner
    handler.run(args[0])
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/xmlstream/handler/callback.py", line 76, in run
    self._pointer(payload)
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/clientxmpp.py", line 280, in _handle_stream_features
    if handler(features) and restart:
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/features/feature_bind/bind.py", line 50, in _handle_bind_resource
    response = iq.send(now=True)
  File "/Users/felipecabral/.virtualenvs/facebook/lib/python2.7/site-packages/sleekxmpp/stanza/iq.py", line 230, in send
    raise IqTimeout(self)
IqTimeout

你知道我做错什么了吗?在

谢谢你!在


Tags: pyselfstreamfacebookbindlibpackagessite