Post a private message to the user frined using Ruby and fb_graph gem?

I want to send a private message to a user's friend using fb_graph. In the docs I can see how to send a post in the users wall but not how to send a message on behalf of that user.

Answers


Unfortunately it cannot be done; Facebook removed the functionality due to abuse (spam etc).

Please refer to: how send message facebook friend through graph api using Accessstoken


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

It seems that is not possible but posting to the user's wall might be an alternative: https://github.com/nov/fb_graph/issues/issue/28/#comment_591398


Need Your Help

Yii2 application git ignore web/index and local configuration

php git yii2

I generate a Yii2 Application then initialized git and commit my change but web/index.php files are in gitignore and not pushed to the repo

Update two tables joined by a pk/fk

sql-server-2008 inner-join

I have two tables with the same ID column PK/FK. I need to update them with data from a third table.