Question

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.

Was it helpful?

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")

OTHER TIPS

I'm assuming you mean registered with your app

You can use FQL instead to built the response you need as the user table has a registered field called is_app_user

SELECT uid, name, is_app_user FROM user where uid in (SELECT uid2 FROM friend WHERE uid1 = me())

Which should return something like

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

If you mean users who are Facebook verified, I think it only works on the authenticated user.

The field is verified

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top