【问题标题】:Not able to send facebook message using xmpp4r_facebook无法使用 xmpp4r_facebook 发送 facebook 消息
【发布时间】:2012-10-03 14:41:56
【问题描述】:

我正在按照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>

【问题讨论】:

    标签: ruby-on-rails ruby facebook facebook-graph-api xmpp4r


    【解决方案1】:

    这个gem的格式是

    -&lt;id&gt;@chat.facebook.com 用于 toid

    没有

    &lt;id&gt;@chat.facebook.com

    注意最初的破折号-(不知道为什么)

    所以之后的回应

    message = Jabber::Message.new to, body
    

    应该是

    &lt;message xmlns='jabber:client' to='-&lt;friend facebook id&gt;@chat.facebook.com'&gt; ... &lt;/&gt;

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

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

    【讨论】:

    • 我更改了它,但仍然无法修复它。这些是我正在使用的更新说明 require 'xmpp4r_facebook' id = '-santhosh.vangapelli@chat.facebook.com' to = '-prateek.mishra@gmail.com' body = "你好,我不是垃圾邮件!"主题 = '来自 ruby​​ 的消息' 消息 = Jabber::Message.new 到,正文 message.subject = 主题客户端 = Jabber::Client.new Jabber::JID.new(id) client.connect client.auth_sasl(Jabber:: SASL::XFacebookPlatform.new(client, '517770868251374', '', '933a3a61307af64f773460b4a7dc2c4e'), nil) client.send message client.close
    • @santu 我不确定用户名是否可以互换,所以您必须使用 Facebook 用户的 id 号也我相信您只能使用 Chat API 在 Facebook 朋友之间进行交流,而不是与任何人交流在 Gmail 中。 Facebook Messages 是一个与 Facebook Chat 完全不同的平台。
    • 我把它改成了@chat.facebook.com' 但还是不行:(
    • @santu 您需要使用 id,例如,如果配置文件是 facebook.com/zuck 并且 id 是 4 那么它将是 to = '-4@chat.facebook.com' 我相信用户名将不适用于这个 gem。跨度>
    • 您能否在实际答案中包含您的 cmets 内容?
    猜你喜欢
    • 1970-01-01
    • 2012-10-03
    • 2023-04-05
    • 2011-11-09
    • 2019-12-31
    • 2013-10-28
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多