通过SleekXMPP发送Facebook消息

通过SleekXMPP发送Facebook消息

本文介绍了通过SleekXMPP发送Facebook消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用sleekXMPP在Facebook聊天上发送消息,并使用此处的答案作为样板:

I am trying to send a message on facebook chat with sleekXMPP, using the answer from here as a boilerplate: Send a Facebook Message with XMPP using Access Tokens in Python

我的代码是

import sleekxmpp

class SendMsgBot(sleekxmpp.ClientXMPP):
    def init(self, jid, recipient, message):

        print "..."

        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)



if __name__ == "__main__":
    xmpp = SendMsgBot(from_id, to_id, unicode(message))

    xmpp.credentials['apikey'] = api_key
    xmpp.credentials['accesstoken'] = o_auth_token

    if xmpp.connect(('chat.facebook.com', 5222)):
        xmpp.process(block=True)
        print("Done")
    else:
        print("Unable to connect")

但是,当我运行脚本时,出现以下错误消息:

However, when I run the script I get this error message:

Traceback (most recent call last):
  File "sendMessagesScript.py", line 33, in <module>
    xmpp = SendMsgBot(from_id, to_id, unicode(message))
  File "/Library/Python/2.7/site-packages/sleekxmpp/clientxmpp.py", line 112, in __init__
    self.register_plugin('feature_starttls')
  File "/Library/Python/2.7/site-packages/sleekxmpp/basexmpp.py", line 264, in register_plugin
    pconfig = self.plugin_config.get(plugin, {})
AttributeError: 'unicode' object has no attribute 'get'

任何想法将不胜感激!

推荐答案

在类SendMsgBot(sleekxmpp.ClientXMPP):中,您需要进行更改

In the class SendMsgBot(sleekxmpp.ClientXMPP):, you need to change

def init(自身,jid,收件人,消息) def __ init __(self,jid,收件人,消息)

def init(self, jid, recipient, message) to def __init__(self, jid, recipient, message)

我希望它能起作用.

这篇关于通过SleekXMPP发送Facebook消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:20