87

I have an application that uses the old REST API call Friends.getAppUsers to get the list of friends for the current user that have authorized my application.

I have read the documentation, how do I do this with the Graph API? What would an example of this be?

Somnath Muluk
  • 46,917
  • 28
  • 204
  • 217
Richard
  • 27,181
  • 8
  • 31
  • 34

8 Answers8

119

I searched around for a while, and I too thought this wasn't possible using Graph API.

However, I posted a similar question, Replacement for old GetAppUsers call to see a user's friends who use my application?, for the specific API I was using and was given a great general answer.

https://graph.facebook.com/me/friends?fields=installed

or more generally

https://graph.facebook.com/{user id}/friends?fields=installed

This returns all friends, with the additional field "installed=true" for those friends who use the application.

Here is it working in the Graph API Explorer:

Community
  • 1
  • 1
Alex
  • 1,980
  • 3
  • 13
  • 19
  • 4
    Yep; I answered your question with this answer: http://facebook.stackoverflow.com/questions/7956639/getappusers-using-c-sharp-opengraph-sdk/7957310#7957310 – Igy Oct 31 '11 at 22:46
  • 2
    For which application does this query checks the installation? – iOS Monster Apr 24 '12 at 06:54
  • 3
    Assuming you're not using any other fields (such as e-mail, birthday, etc.), for completeness use `/me/friends?fields=id,name,installed`, which preserves field order and the standard information that is returned without `?fields=` being defined (true on 2012/12/05). – plasmid87 Dec 05 '12 at 16:54
  • 5
    At the time of this writing, this query returns all the friends (even for which `installed` is not true). We need to manually check whether the `installed` field exists for each user. – Pankaj Bhambhani Jan 01 '13 at 15:51
  • Yes that is correct, I have edited the answer to make that clear that you get all friends and you have to check for which ones have the installed flag. – Alex Jan 02 '13 at 16:57
  • as of API 2.0, //friends/ returns only friends who installed the app. https://developers.facebook.com/docs/apps/changelog#v2_0 – guyblank Apr 10 '15 at 17:48
  • That's it! Just add the need for checking the 'installed' parameter, to complete this answer – Mladen Janjetovic Apr 22 '15 at 09:19
27

This can be done with FQL.

SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ?)
AND is_app_user = 1

QED!

loungerdork
  • 971
  • 11
  • 14
  • 1
    I originally used this query and because of the latency now I just get all friends via the graph api and then filter on my application side instead. – Richard Oct 28 '10 at 17:03
  • Can you give more details about the latency? Is it the query taking too long to respond? I have been testing with a FB account with about 300+ friends and the response time has been a couple of seconds (2 to 4), which is not too bad IMO. – loungerdork Nov 01 '10 at 04:42
  • 1
    Yeah, that's roughly what I see. The graph API takes on the order of 500ms to return 400+ friends so I prefer to get them all and then filter on my side. – Richard Nov 02 '10 at 22:09
  • 3
    you can also use `me()` instead of the ? – philfreo Sep 23 '11 at 00:40
8

Yes, the Graph API is horribly documented. I don't see any documentation for an "application" type, but they do reference an application's info in the docs:

https://graph.facebook.com/2439131959

So, perhaps you can get the application's members using the Group syntax?

https://graph.facebook.com/2439131959/members

You'll need an authenticated session to test it. Otherwise, it looks like Facebook is pushing us to use FQL to send queries directly:

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

You can execute FQL queries by fetching https://api.facebook.com/method/fql.query?query=QUERY. You can specify a response format as either XML or JSON with the format query parameter.

So you can pass a FQL query to get information about your application.

typeoneerror
  • 51,338
  • 32
  • 124
  • 213
  • 2
    Ugh. Seems light switching to the graph api is more of a headache that I had originally hoped. – Richard May 20 '10 at 15:43
  • 4
    It's probably easier to do everything you need (except publishing) using FQL. The Graph API, at worst, won't give you everything you need, and at best, will make it irritatingly hard to find out how to do so. – Daniel Schaffer Jul 01 '10 at 04:04
6

Old REST API:

$facebook->api_client->friends_getAppUsers();

New Graph API:

$facebook->api(array('method' => 'friends.getAppUsers'));
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
jana
  • 85
  • 1
  • 1
5

I've done a lot of investigations on this issue. From what I can tell, there is no way to do Friends.getAppUsers using Graph API. The latest SDKs provided by Facebook all use the old REST API to get friends using the application.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Richard
  • 27,181
  • 8
  • 31
  • 34
  • 6
    This is pretty old and no longer the right answer. Check Alex's answer at the top. – Bach Aug 11 '12 at 02:43
  • It might not be the right answer, but it is the OP's answer, and it's clearly better to upvote yourself than mark the correct answer as correct because ego. – Ajax Aug 18 '16 at 17:39
4

Using restFB, I did the following (thanks Igy / Alex for the guidance). Note that Facebook returns an array of friend IDs with "installed"=true if the user is installed (as can be seen here).

First extend the User class, adding an installed field:

import com.restfb.Facebook;
import com.restfb.types.User;

public class InstalledUser extends User {

    @Facebook
    private boolean installed;

    public InstalledUser() {        
    }

    public boolean getInsatlled() {
        return installed;
    }
}

Next, using the DefaultFacebookClient:

FacebookClient facebook = new DefaultFacebookClient(pFacebookAccessToken);
Connection<InstalledUser> installedFacebookUsers = facebook.fetchConnection("/" + pFacebookId + "/friends", InstalledUser.class, Parameter.with("fields", "installed"));        
for (List<InstalledUser> friends : installedFacebookUsers) {
    for (InstalledUser friend : friends) {
        if (friend.getInsatlled()) {
            // Add friend.getId() to a list of ID, or whatever
        }
    }
}
Ben Flynn
  • 17,294
  • 18
  • 92
  • 133
1

The workaround is to do the filtering yourself. Presumably, you have all the uid's of the users who have signed up for your application sitting in your own database. So first get all the users' friends' uids, and select the users from your database who have matching uids.

The new Facebook Graph API program seems very poorly executed and not quite thought through. It seems they rushed to publish it for Facebook f8 before it was mature, and lots of functionality is missing that was available before.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
schung
  • 11
  • 1
0

You can still call the old REST API's in the new Graph API. That is prefectly valid.

An alternative way is to use FQL to get the application user's friends.

I'm not sure if there's a way to do this using just Graph API.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Roozbeh15
  • 3,607
  • 6
  • 25
  • 29