开发者

Sending private messages to facebook accounts using ruby on rails

I need to make the user able to send private message to his friends through facebook. In PHP there is somethin开发者_如何学运维g called Openinviter which can grab the contacts of nearly any social network or email provider.

I found a gem on rails called contacts that does the same thing for email providers. It can grab users friends from email providers but not social networks.

Is there a similar gem or plugin that I could use to make my application send private messages to facebook contacts?

Thanks,


You can use Facebook Chat API to send private messages, here is an example in Ruby using xmpp4r_facebook gem:

sender_chat_id = "-#{sender_uid}@chat.facebook.com"
receiver_chat_id = "-#{receiver_uid}@chat.facebook.com"
message_body = "message body"
message_subject = "message subject"

jabber_message = Jabber::Message.new(receiver_chat_id, message_body)
jabber_message.subject = message_subject

client = Jabber::Client.new(Jabber::JID.new(sender_chat_id))
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client,
   ENV.fetch('FACEBOOK_APP_ID'), facebook_auth.token,
   ENV.fetch('FACEBOOK_APP_SECRET')), nil)
client.send(jabber_message)
client.close


No, sending private messages via email you've fetched from facebook's API or from a facebook app via the API seems to be against the current API TOS/Policies has in effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜