Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Facebook:如何使用xmpp以粉丝页面的形式发送私人消息_Python_Facebook_Api_Xmpp - Fatal编程技术网

Python Facebook:如何使用xmpp以粉丝页面的形式发送私人消息

Python Facebook:如何使用xmpp以粉丝页面的形式发送私人消息,python,facebook,api,xmpp,Python,Facebook,Api,Xmpp,几天来,我一直在寻找解决我问题的办法,但都没有成功,我决定寻求帮助 我正在尝试使用带有python的XMPP协议向facebook用户发送一条私人消息,作为我的粉丝页面 我正在使用下面的代码创建客户端: import sleekxmpp class SendMsgBot(sleekxmpp.ClientXMPP): def __init__(self, jid, recipient, message): sleekxmpp.ClientXMPP.__init__(sel

几天来,我一直在寻找解决我问题的办法,但都没有成功,我决定寻求帮助

我正在尝试使用带有python的XMPP协议向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)
这是我使用上面创建的客户端发送消息的代码:

from fbxmpp import SendMsgBot

jid = '1000021...@chat.facebook.com'
to = '1351...@chat.facebook.com'
msg = 'Hey  anything , how is it going?'

xmpp = SendMsgBot(jid, to, unicode(msg))

xmpp.credentials['api_key'] = '599641.....' 
xmpp.credentials['access_token'] = 'CAACEdEose0cBACVTezXXZATDZAZBucX8fTUB0a....'

if xmpp.connect(('chat.facebook.com', 5222)):
    xmpp.process(block=True)
    print("Done")
else:
    print("Unable to connect.")
在上面的代码中使用我的facebook登录名和密码,我没有得到任何错误。但是我需要使用我的粉丝页面发送消息

我已成功使用api_密钥和access_令牌进行身份验证,但控制台冻结了一段时间,并显示以下消息:

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
知道我做错了什么吗


谢谢大家!

同样,这应该在sleekxmpp 1.2.4中修复。

您使用的是sleekxmpp的最新版本吗?我怀疑这个问题可能与此有关-错误表明库正在等待它实际收到的IQ结果,因此可能它没有预料到它得到的“from”属性(用户的裸JID)。“最近”似乎包括1.2.0版。我的工作中安装的版本是sleekxmpp==1.2.3您认为安装以前的1.2版可以解决这个问题吗?你觉得值得参加这个测试吗?看来1.2.0是最新版本,没有任何变化。如果它与1.2.0兼容,则应在sleekxmpp中将其报告为一个bug。谢谢,它成功了。删除了1.2.3版,安装了1.1.11版。现在正在使用api和acess_令牌进行身份验证。我真正喜欢做但仍然不工作的是发送一条私人消息,将我的fanpage作为消息的所有者,但无法这样做。谢谢,我将继续搜索下一步。