I am following the instructions presented in http://dalibornasevic.com/posts/35-how-to-send-private-messages-with-facebook-api to send message to my friend and currently testing from command line. Following is the code I am using. When I open my facebook account and check the sent messages I don't see the message I am trying to send through command line. I just don't understand the mistake I am making.
1.9.3-p194 :017 > require 'xmpp4r_facebook'
=> true
1.9.3-p194 :00 3 > id = '-<my facebook id>@chat.facebook.com'
=> "-<my facebook id>@chat.facebook.com"
1.9.3-p194 :00 4 > to = '-<friend facebook id>@chat.facebook.com'
=> "-< friend's facebook id>@chat.facebook.com"
1.9.3-p194 :00 5 > body = "hello, Im not spam!"
=> "hello, Im not spam!"
1.9.3-p194 :00 6 > subject = 'message from ruby'
=> "message from ruby"
1.9.3-p194 :00 7 > message = Jabber::Message.new to, body
=> <message xmlns='jabber:client' to='-<friend facebook id>@chat.facebook.com'> ... </>
1.9.3-p194 :00 8 > message.subject = subject
=> "message from ruby"
1.9.3-p194 :00 9 >
1.9.3-p194 :010 > client = Jabber::Client.new Jabber::JID.new(id)
=> #<Jabber::Client:0x007fc47e4d8498 @fd=nil, @status=1, @xmlcbs=#<Jabber::CallbackList:0x007fc47e4d8470 @list=[]>, @stanzacbs=#<Jabber::CallbackList:0x007fc47e4d8420 @list=[]>, @messagecbs=#<Jabber::CallbackList:0x007fc47e4d83d0 @list=[]>, @iqcbs=#<Jabber::CallbackList:0x007fc47e4d8380 @list=[]>, @presencecbs=#<Jabber::CallbackList:0x007fc47e4d8330 @list=[]>, @send_lock=#<Mutex:0x007fc47e4d82e0>, @last_send=2012-10-12 23:29:34 +0530, @exception_block=nil, @tbcbmutex=#<Mutex:0x007fc47e4d8290>, @threadblocks=[], @wakeup_thread=nil, @streamid=nil, @streamns="jabber:client", @features_sem=#<Jabber::Semaphore:0x007fc47e4d8218 @tickets=0, @lock=#<Mutex:0x007fc47e4d81f0>, @cond=#<ConditionVariable:0x007fc47e4d81c8 @waiters=[], @waiters_mutex=#<Mutex:0x007fc47e4d8178>>>, @parser_thread=nil, @processing=0, @host=nil, @port=nil, @allow_tls="constant", @tls=false, @ssl_capath=nil, @ssl_verifycb=nil, @features_timeout=10, @keepalive_interval=60, @use_ssl=false, @jid=-<my facebook id>@chat.facebook.com>
1.9.3-p194 :011 > client.connect
=> #<Jabber::Client:0x007fc47e4d8498 @fd=#<OpenSSL::SSL::SSLSocket:0x007fc47c852260>, @status=2, @xmlcbs=#<Jabber::CallbackList:0x007fc47e4d8470 @list=[]>, @stanzacbs=#<Jabber::CallbackList:0x007fc47e4d8420 @list=[]>, @messagecbs=#<Jabber::CallbackList:0x007fc47e4d83d0 @list=[]>, @iqcbs=#<Jabber::CallbackList:0x007fc47e4d8380 @list=[]>, @presencecbs=#<Jabber::CallbackList:0x007fc47e4d8330 @list=[]>, @send_lock=#<Mutex:0x007fc47e4d82e0>, @last_send=2012-10-12 23:29:35 +0530, @exception_block=nil, @tbcbmutex=#<Mutex:0x007fc47e4d8290>, @threadblocks=[], @wakeup_thread=nil, @streamid="10BAB5BB", @streamns="jabber:client", @features_sem=#<Jabber::Semaphore:0x007fc47e4d8218 @tickets=0, @lock=#<Mutex:0x007fc47e4d81f0>, @cond=#<ConditionVariable:0x007fc47e4d81c8 @waiters=[], @waiters_mutex=#<Mutex:0x007fc47e4d8178>>>, @parser_thread=#<Thread:0x007fc47c852008 sleep>, @processing=0, @host="chat.facebook.com", @port=5222, @allow_tls="constant", @tls=true, @ssl_capath=nil, @ssl_verifycb=nil, @features_timeout=10, @keepalive_interval=60, @use_ssl=false, @jid=santhosh.vangapelli@chat.facebook.com, @socket=#<OpenSSL::SSL::SSLSocket:0x007fc47c852260>, @stream_mechanisms=["X-FACEBOOK-PLATFORM", "DIGEST-MD5"], @stream_features={}, @parser=#<Jabber::StreamParser:0x007fc47c852030 @stream=#<OpenSSL::SSL::SSLSocket:0x007fc47c852260>, @listener=#<Jabber::Client:0x007fc47e4d8498 ...>, @current=nil, @started=true>, @keepaliveThread=#<Thread:0x007fc47c899868 run>>
1.9.3-p194 :012 > client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client, '<App ID>', '<access token>', 'App Secret'), nil) => <iq xmlns='jabber:client' type='result' id='2071'> ... </>
1.9.3-p194 :013 > client.send message
=> nil
1.9.3-p194 :014 > client.close
=> #<Thread:0x007fc47c899868 dead>
The format for this gem is
-<id>@chat.facebook.com
for to
and id
Not
<id>@chat.facebook.com
Notice the initial dash -
(Not sure why)
So the response after
message = Jabber::Message.new to, body
should be
<message xmlns='jabber:client' to='-<friend facebook id>@chat.facebook.com'> ... </>
I'm not sure whether usernames are interchangeable, so you must use the id number of the Facebook user also I believe you can only use the Chat API to communicate between Facebook friends, not to anyone in Gmail. Facebook Messages is a different platform altogether from Facebook Chat.
You need to use ids, for example, if the profile is facebook.com/zuck
and the id is 4
then it would be to = '-4@chat.facebook.com'
Usernames will not work for this gem I believe.