Xmpppy and Facebook integration

I am trying to create a very simple script that uses python xmpppy to send a message via facebook chat.

import xmpp
FACEBOOK_ID = " username@chat.facebook.com "
PASS = "password"
SERVER = "chat.facebook.com"
jid = xmpp.protocol.JID (FACEBOOK_ID)
C = xmpp.Client (jid.getDomain (), debug = [])
if not C.connect ((SERVER, 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 (" friend@chat.facebook.com ", "Hello world",))

This code works to send a message via gchat, however, when I try using facebook, I get this error:

An error occurred while searching for _xmpp-client._tcp.chat.facebook.com

When I remove @ chat.facebook.com from FACEBOOK_ID, I get this instead:

File "gtalktest.py", line 11, in 
    if not C.connect ((SERVER, 5222)):
  File "/home/john/xmpppy-0.3.1/xmpp/client.py", line 195, in connect
    if not CommonClient.connect (self, server, proxy, secure, use_srv) or secureNone and not secure: return self.connected
  File "/home/john/xmpppy-0.3.1/xmpp/client.py", line 179, in connect
    if not self.Process (1): return
  File "/home/john/xmpppy-0.3.1/xmpp/dispatcher.py", line 302, in dispatch
    handler ['func'] (session, stanza)
  File "/home/john/xmpppy-0.3.1/xmpp/dispatcher.py", line 214, in streamErrorHandler
    raise exc ((name, text))
xmpp.protocol.HostUnknown: (u'host-unknown ',' ')

, xmpp, :

/home/john/xmpppy-0.3.1/xmpp/auth.py:24: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha,base64,random,dispatcher
/home/john/xmpppy-0.3.1/xmpp/auth.py:26: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5

, , , . !

+3
2

. . UserName facebook (, ), Caps. . , , , .

+2
import xmpp

FACEBOOK_ID = "username@chat.facebook.com"
PASS = "password"
SERVER = "chat.facebook.com"

jid=xmpp.protocol.JID(FACEBOOK_ID)

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

if not client.connect((SERVER,5222)):
    raise IOError('Can not connect to server.')
if not client.auth(jid.getNode(),PASS):
    raise IOError('Can not auth with server.')


message = xmpp.protocol.Message(frm=client.Bind.bound[0], to="-<#_ID_OF_FRIEND>@chat.facebook.com", typ="chat", body="Hello world",)

client.SendAndWaitForResponse(message)

. , , Client.SendAndWaitForResponse Client.send;)

+1

Source: https://habr.com/ru/post/1786315/


All Articles