Facebook App Users List

14,510

Solution 1

This is I believe the FQL query

$facebook->api(array('method' => 'fql.query', 'query' => "SELECT uid FROM user WHERE is_app_user = '1' AND uid IN (SELECT uid2 FROM friend WHERE uid1 = '" . $user_id . "');"));

(I use java and JS APIs so the syntax may not be exactly correct)

The documentation for the user and friend queries are here:

http://developers.facebook.com/docs/reference/fql/user/

http://developers.facebook.com/docs/reference/fql/friend/

Solution 2

Use this query in JS

function getAppFriends()
{

    var fql = "SELECT uid, name, pic_square, is_app_user 
               FROM user 
               WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 
               OR uid IN(SELECT uid1 FROM friend WHERE uid2=me()) 
               ORDER BY  name";

    var query = FB.Data.query(fql);

    query.wait(function(responseFromFb){

       if(responseFromFb!=null){

           // Read the responseFromFb and check for 
           // is_app_user = true and list them out the way 
           // you want to.

       }

    });// anonymus function closes here
} //function ends here
Share:
14,510

Related videos on Youtube

captainclam
Author by

captainclam

I'm an Aussie web developer based in Brisbane. I have a Software Engineering degree, and more importantly, about 10 years of industry experience. I specialise in CoffeeScript & NodeJS development, but also have experience with a wide range of technologies, and always love to learn new ones.

Updated on June 04, 2022

Comments

  • captainclam
    captainclam almost 2 years

    I am fairly new to the Facebook APIs. I want to get a list of my friends who have also installed my app. (The idea being you can then start a game with them).

    This gives a list of my friends:

    FB.api('/me/friends', ...
    

    This gives my app info:

    FB.api('/myappid', ...
    

    What I want is "my friends who also have this app installed"

    I thought it might be this:

    FB.api('/myappid/accounts', ...
    

    I was hoping that would at least give me my Developers, Administrators or Testers, but no such luck. http://developers.facebook.com/docs/test_users/ http://developers.facebook.com/docs/ApplicationSecurity/

    My feeling is perhaps I have to use FQL to construst a query that says something like

    (psuedocode)
    SELECT
    FROM my_friends
    WHERE uid IN (
        SELECT uid
        FROM app_users
        WHERE appid = myappid
    )
    

    Any advice would be greatly appreciated.

    Note, I have seen this post: FaceBook app: retrieve list of ids of my application's users

    I am keeping a local list of Facebook User's IDs that belong to my site, and I am actually able to achieve my goal by doing the following, but I am sure there must be a better way:

    $facebookFriendIds = array();
    $friends = $this->facebook->api('/me/friends');
    foreach ($friends['data'] as $friend) {
        $facebookFriendIds[] = $friend['id'];
    }
    
    $this->friends = Doctrine_Core::getTable('User')->createQuery()
        ->whereIn('fb_user_id', $facebookFriendIds)
        ->execute();
    

Related