0

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.

rtacconi
  • 14,317
  • 20
  • 66
  • 84

3 Answers3

2

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
Dalibor Nasevic
  • 331
  • 3
  • 6
0

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

Community
  • 1
  • 1
Robarondaz
  • 555
  • 5
  • 12
0

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

rtacconi
  • 14,317
  • 20
  • 66
  • 84