Unable to connect to Facebook Chat Via Python, using xmpppy library

1

I am trying to write a script in python to connect to facebook chat. I am just not able to. Here is the code:

import xmpp
FACEBOOK_ID = "firesofmay@chat.facebook.com"
PASS = "password"

jid=xmpp.protocol.JID(FACEBOOK_ID)

C=xmpp.Client(jid.getDomain(),debug=['always'])

if not C.connect(("chat.facebook.com",5222)):
    raise IOError('Can not connect to server.')

if not C.auth(jid.getNode(),PASS):
    raise IOError('Can not auth with server.')

C.send(xmpp.protocol.Message("gmjain@chat.facebook.com","Hello world from script",))

This is the error I get:

An error occurred while looking up _xmpp-client._tcp.chat.facebook.com

And this is the debugger output here.

Which shows that I do get authenticated (Line 136) , but still the message is not sent somehow. I am really stuck at this for days now.

firesofmay

Posted 2012-02-08T14:50:12.800

Reputation: 113

Answers

0

As @grawity pointed out, you need to get the JIDs which you can get by adding following code to your script.

In your code after authenticating with server you can ask the server for the list of contacts. In your code add this,

C.sendInitPresence(requestRoster=1)
rosterobject = C.getRoster()

If you want to just check/print the JIDs, you can do this with following loop.

for i in rosterobject.getItems():
    print i

In roster object you should have contacts aka JIDs, Now use that JID in the next statement,

C.send(xmpp.Message("jidfromrosterobj@domain.tld","Hello world from script",))

I hope this solves your problem.

Muneeb

Posted 2012-02-08T14:50:12.800

Reputation: 16

0

username@chat.facebook.com JIDs are only valid during authentication. For sending messages you have to use -profileid@chat.facebook.com JIDs, which you can find out from your XMPP roster. (Sending a message to yourself does not work, though.)

user1686

Posted 2012-02-08T14:50:12.800

Reputation: 283 655