不能使用xmpp4r_facebook发送Facebook消息 [英] Not able to send facebook message using xmpp4r_facebook

查看:163
本文介绍了不能使用xmpp4r_facebook发送Facebook消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>


推荐答案

这个gem的格式是

- < id> @ chat.facebook.com for to and id

-<id>@chat.facebook.com for to and id

< id> @ chat.facebook.com

注意初始短划线 - (不知道为什么)

Notice the initial dash - (Not sure why)

所以在

message = Jabber::Message.new to, body

应该是

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

我不确定用户名是否可互换,所以您必须使用Facebook的ID号用户也相信您只能使用Chat API在Facebook的朋友之间通信,而不是Gmail中的任何人。 Facebook Message是Facebook Chat的完全不同的平台。

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.

您需要使用ids,例如,如果配置文件是 facebook.com/zuck ,而id为 4 然后它将是 to ='-4@chat.facebook.com'用户名将不适用于此宝石我相信。

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.

这篇关于不能使用xmpp4r_facebook发送Facebook消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆