9

Is there any way to post a Facebook application invite from Ruby on Rails, e.g. by deploying Koala?

Looks to be impossible at the glance. Any workarounds other than simply posting to a wall?

Ain Tohvri
  • 2,987
  • 6
  • 32
  • 51
  • 2
    Have you tried something like this? http://blog.otherscreen.com/2011/06/invite-facebook-friends-to-your-rails-app-omniauth-javascript/ – mnelson Nov 09 '11 at 16:17
  • 2
    if this was possible it would be a MAJOR spam generator... imagine if (with out user interaction) an application could just decide to send app invites to all of a users friends... spam-a-thon if u ask me... TBH - I really hope this is not possible... – Lix Nov 14 '11 at 11:23
  • apologies for the pessimistic vibes :P – Lix Nov 14 '11 at 15:00
  • @Lix agreed indeed and as far as I've heard, this seems to be the case. – Ain Tohvri Nov 14 '11 at 23:24
  • 1
    @mikeonrails Link not working – Benjamin Crouzier Apr 09 '13 at 12:17

2 Answers2

23

Actually mikeonrails gave a correct link - the Requests dialog is the way to invite friends to your app and send them other types of requests. It does require user interaction though (just as the video shows), for requests sent to users who don't have the application installed.

And now for the details. There are 2 types of requests that you can send:

  • user-generated requests: these can be sent to users who don't have the application installed (ie. application invite). They can only be sent using the Javascript SDK (or the iOS or Android SDKs but I don't think you're interested in those) and they do require user interaction. It will consist of a pop-up that will either display a selection (made by you) of his friends or a friend selector and a send button to send them your message.
  • app-generated requests: these can only be sent to users who have the application installed, but can be sent without user interaction.

The code for user-generated requests is like this (using the Javascript SDK):

// this will show the pop-up dialog with a friend selector
// add a `to: 'friend_id1,friend_id2` to skip the friend selector
FB.ui({
    method: 'apprequests',
    message: 'My Great Request'
}, requestCallback);

For the app-generated requests you can use Koala like this:

user = Koala::Facebook::API.new(user_token)
user.put_object("user_with_app_installed_id", "apprequests", {:message => "Would you like to be friends?")

So, the conclusion is that you cannot invite a user's friends to your application without his approval, but you can make it really simple for him to do it (2 clicks).

If you'd like to read more:

deviousdodo
  • 9,177
  • 2
  • 29
  • 34
4

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

UPDATE: Facebook chat API has been deprecated so it is not possible to use this solution anymore.

Kkulikovskis
  • 2,028
  • 16
  • 28
Dalibor Nasevic
  • 331
  • 3
  • 6