我正在按照 http://dalibornasevic.com/posts/35-how-to-send-private-messages-with-facebook-api 中提供的说明进行操作向我的 friend 发送消息,目前正在从命令行进行测试。以下是我正在使用的代码
require 'xmpp4r_facebook'
id = '<my facebook id>@chat.facebook.com'
to = '<my friend facebook id>@chat.facebook.com'
body = "hello, Im not spam!"
subject = 'message from ruby'
message = Jabber::Message.new to, body
message.subject = subject
client = Jabber::Client.new Jabber::JID.new(id)
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client, '<App ID>', '<access token got from https://developers.facebook.com/tools/explorer>', 'App Secret'), nil)
我收到错误
RuntimeError: not-authorized
from /Users/apple/.rvm/gems/ruby-1.9.3-p194/gems/xmpp4r_facebook-0.1.1/lib/xmpp4r_facebook.rb:103:in `auth'
from /Users/apple/.rvm/gems/ruby-1.9.3-p194/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:171:in `auth_sasl'
from (irb):12
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
最佳答案
听起来您没有按照消息所述授予 xmpp_login
权限
not-authorized
如果您拥有正确的权限,它应该可以工作,并且您应该得到类似于
的响应<iq xmlns='jabber:client' type='result' id='2027'> ... </>
使用 https://developers.facebook.com/tools/debug 检查您的访问 token
关于ruby-on-rails - 使用 xmpp4r_facebook 发送消息时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12862304/