Facebook 'Friends.getAppUsers' using Graph API
Asked Answered
K

8

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?

Kosse answered 6/5, 2010 at 23:2 Comment(0)
K
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.

Kosse answered 17/6, 2010 at 22:20 Comment(2)
This is pretty old and no longer the right answer. Check Alex's answer at the top.Charinile
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.Piperonal
G
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:

Guppy answered 31/10, 2011 at 22:0 Comment(7)
Yep; I answered your question with this answer: facebook.#7957139Inquietude
For which application does this query checks the installation?Brahmanism
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).Canaveral
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.Observant
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.Guppy
as of API 2.0, /<user_id>/friends/ returns only friends who installed the app. developers.facebook.com/docs/apps/changelog#v2_0Naos
That's it! Just add the need for checking the 'installed' parameter, to complete this answerTackle
N
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!

Nalda answered 27/10, 2010 at 9:27 Comment(4)
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.Kosse
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.Nalda
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.Kosse
you can also use me() instead of the ?Blackthorn
P
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.

Pileup answered 18/5, 2010 at 16:45 Comment(2)
Ugh. Seems light switching to the graph api is more of a headache that I had originally hoped.Kosse
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.Proportionate
B
6

Old REST API:

$facebook->api_client->friends_getAppUsers();

New Graph API:

$facebook->api(array('method' => 'friends.getAppUsers'));
Boesch answered 28/10, 2010 at 0:8 Comment(1)
This SDK method call uses the old rest api under the covers. It's not the graph api :-(Kosse
K
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.

Kosse answered 17/6, 2010 at 22:20 Comment(2)
This is pretty old and no longer the right answer. Check Alex's answer at the top.Charinile
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.Piperonal
M
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
        }
    }
}
Megagamete answered 21/12, 2011 at 21:27 Comment(0)
T
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.

Trager answered 12/8, 2010 at 4:40 Comment(0)
S
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.

Sandpaper answered 11/1, 2011 at 23:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.