无法使用xmpp4r_facebook发送脸书消息



我正在按照 http://dalibornasevic.com/posts/35-how-to-send-private-messages-with-facebook-api 中的说明向我的朋友发送消息,目前正在从命令行进行测试。以下是我正在使用的代码。当我打开我的Facebook帐户并检查已发送的消息时,我没有看到我尝试通过命令行发送的消息。我只是不明白我所犯的错误。

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>

此 gem 的格式为

-<id>@chat.facebook.com toid

<id>@chat.facebook.com

注意初始破折号-(不确定原因)

所以之后的回应

message = Jabber::Message.new to, body

应该是

<message xmlns='jabber:client' to='-<friend facebook id>@chat.facebook.com'> ... </>

我不确定用户名是否可以互换,所以你必须使用Facebook用户的ID号,我相信你只能使用聊天API在Facebook朋友之间进行交流,而不是与Gmail中的任何人交流。Facebook Messages是一个与Facebook Chat完全不同的平台。

您需要使用 id,例如,如果配置文件facebook.com/zuck并且 id 4那么我相信用户名不适用于此宝石to = '-4@chat.facebook.com'

相关内容

  • 没有找到相关文章

最新更新