Connecting to Facebook Chat using SleekXMPP
NickName:Paulo Freitas Ask DateTime:2012-05-24T14:58:04

Connecting to Facebook Chat using SleekXMPP

I'm using this sample code to connect to Facebook Chat over XMPP:

#!/usr/bin/python
import sleekxmpp
import logging
logging.basicConfig(level=logging.DEBUG)

def session_start(event):
    chatbot.send_presence()
    print('Session started')
    chatbot.get_roster()

def message(msg):
    if msg['type'] in ('chat','normal'):
        print('msg received')
        print(msg['body'])

        msg.reply('Thanks').send()

jid = '[email protected]'
password = 'mypassword'
server = ('chat.facebook.com', 5222)

chatbot = sleekxmpp.ClientXMPP(jid,password)
chatbot.add_event_handler('session_start', session_start)
chatbot.add_event_handler('message', message)
chatbot.auto_reconnect = True
chatbot.connect(server)
chatbot.process(block=True)

Everything seems to be Ok, but when I run that code, I can't connect to Facebook server:

DEBUG:sleekxmpp.basexmpp:setting jid to [email protected]
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120)  STARTTLS Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120)  Resource Binding Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-3920)  Start Session Stream Feature
DEBUG:sleekxmpp.basexmpp:Loaded Plugin (RFC-6120)  SASL Stream Feature
DEBUG:sleekxmpp.xmlstream.xmlstream:Trying to connect to chat.facebook.com:5222
DEBUG:sleekxmpp.xmlstream.xmlstream:Connecting to chat.facebook.com:5222
ERROR:sleekxmpp.xmlstream.xmlstream:Could not connect to chat.facebook.com:5222. Socket Error #111: Connection refused
DEBUG:sleekxmpp.xmlstream.xmlstream:Trying to connect to chat.facebook.com:5222
DEBUG:sleekxmpp.xmlstream.xmlstream:Waiting 1.97953654103 seconds before connecting.
...

Am I missing something here?

Copyright Notice:Content Author:「Paulo Freitas」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10732616/connecting-to-facebook-chat-using-sleekxmpp

More about “Connecting to Facebook Chat using SleekXMPP” related questions

Connecting to Facebook Chat using SleekXMPP

I'm using this sample code to connect to Facebook Chat over XMPP: #!/usr/bin/python import sleekxmpp import logging logging.basicConfig(level=logging.DEBUG) def session_start(event): chatbot.

Show Detail

Send facebook messages via SleekXMPP

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 My code is import slee...

Show Detail

SleekXMPP proxy issue

I am using SleekXMPP to integrate a chat bot with Facebook. When I am not behind a proxy, I get the expected behavior. But when I am behind a proxy, the connection is not established. I took a loo...

Show Detail

Sendind facebook messages with sleekxmpp without providing password

I have a simple sleekxmpp messaging bot that sends facebook messages (source: http://sleekxmpp.com/getting_started/sendlogout.html): class SendMsgBot(sleekxmpp.ClientXMPP): def __init__(self, jid,

Show Detail

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

After days searching unsuccessfully for a solution to my problem, I've decided to ask for help. I'm trying to send a private message to a facebook user as my fan page using XMPP protocol with pyt...

Show Detail

Sending Messages with sleekxmpp hangs in process()

So I've got this little Python script that get's triggerd from an insert into a PostgreSQL table and deliveres XMPP Messages. Worked like a charm. Now with an upgrade to Python 3.8 (from 3.5) and

Show Detail

XMPPError connecting to chat.facebook.com (Permission denied) logging in to facebook chat with asmack

As you may know, there's not a single organized documentation on how to properly login to Facebook using the asmack library. I've somehow managed to find some codes in the net to at least allow me to

Show Detail

SleekXMPP automatically accept all chat room invites

I want to use SleekXMPP and automatically accept all chat room invites that are sent to me. I know that the xep_0045 plugin can detect when I receive an invite, as I am notified in the debugger. I am

Show Detail

Facebook Chat, Application, XMPP gives first test account during resource request

I have created two facebook test accounts for my test application. Both test accounts have xmpp_login extended permissions. I am using SleekXMPP python library to connect (with second account) to the

Show Detail

Twisted - SleekXMPP compatibility

I am making a XMPP middleware in python which listens on a an address(host,port) and when it receives some connection on that port, it sends a XMPP message to a jid(XMPP user) on a server. A quick

Show Detail