gpt4 book ai didi

python - Facebook : How to send a private message as a fanpage using xmpp

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:32 26 4
gpt4 key购买 nike

在为我的问题寻找解决方案多年未果后,我决定寻求帮助。

我正在尝试使用带有 python 的 XMPP 协议(protocol)向 facebook 用户发送私有(private)消息作为我的粉丝页面。

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

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_key 和 access_token 进行身份验证,但控制台会卡住一段时间并显示以下消息:

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

知道我做错了什么吗?

谢谢!

最佳答案

作为mentioned over at Github , 这应该在 sleekxmpp 1.2.4 中修复。

关于python - Facebook : How to send a private message as a fanpage using xmpp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21757544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com