使用sleekxmpp发送facebook消息而不提供密码

时间:2013-12-05 22:15:07

标签: python facebook xmpp facebook-chat

我有一个简单的sleekxmpp消息机器人发送facebook消息(来源:http://sleekxmpp.com/getting_started/sendlogout.html):

class SendMsgBot(sleekxmpp.ClientXMPP):

def __init__(self, jid, password, recipient, message):
    sleekxmpp.ClientXMPP.__init__(self, jid, password, sasl_mech='X-FACEBOOK-PLATFORM')

    self.recipient = recipient
    self.msg = message

    self.add_event_handler("session_start", self.start)

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 split.apps.sapi.utils import SendMsgBot
jid = 'xxx@chat.facebook.com'
to = '-xxx@chat.facebook.com'
msg = "Try out message"

xmpp = SendMsgBot(jid, None, to, msg)
xmpp.credentials['access_token']  = [access token provided by Graph API]
xmpp.credentials['api_key']= [API key of our application]
xmpp.auto_reconnect = True

if xmpp.connect(('chat.facebook.com', 5222)):
    xmpp.process(block=True)

我的问题是,当我不提供正确的Facebook密码时,它不会发送消息。将认证机制硬编码为sasl_mech ='X-FACEBOOK-PLATFORM'并没有帮助。当我向SendMsgBot初始化添加正确的密码时,它会毫无问题地发送消息:

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

要求应用程序的用户提供facebook密码是无稽之谈,我认为访问令牌和facebook id应该足以使这项工作。

0 个答案:

没有答案