Search code examples
ruby-on-railsfacebookkoalarabl

Render Facebook friends with 'registered' attribute


Basycally what I would like to do is to :

  • Get the Facebook friends of a the current user
  • Render this collection while differentiating user who are already registered with my app to other users by adding a 'registered' attribute set to true or false to each item of this collection

I've managed to retrieve the Facebook friends of the current user and serve it to my app like so

UserController

  def facebook_friends
    @friends = graph.get_connections("me", "friends")
  end

RABL

object false
node :data do @friends
end

It returns something like:

{
  data: [{
    'id': '23456789'
    'name': 'Bobby Brown'
  }, {
    'id': '23456788'
    'name': 'Bobby Black'
  }]
}

but what I would like is something like this:

{
  data: [{
    'id': '23456789'
    'name': 'Bobby Brown',
    'registered': true
  }, {
    'id': '23456788'
    'name': 'Bobby Black',
    'registered': false
  }]
}

But I have no idea how to do the second part without wasting too much resources.


Solution

  • There is simple Graph API query for that.

    me/friends?fields=id,name,installed
    

    https://developers.facebook.com/tools/explorer/

    It returns JSON. Users who installed app have installed: true

    @graph.get_connections('me','friends',:fields=>"id,name,installed")