Facebook 'Friends.getAppUsers' using Graph API

FacebookFacebook Graph-ApiFacebook Friends

Facebook Problem Overview


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?

Facebook Solutions


Solution 1 - Facebook

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:

Solution 2 - Facebook

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!

Solution 3 - Facebook

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.

Solution 4 - Facebook

Old REST API:

$facebook->api_client->friends_getAppUsers();

New Graph API:

$facebook->api(array('method' => 'friends.getAppUsers'));

Solution 5 - Facebook

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.

Solution 6 - Facebook

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
        }
    }
}

Solution 7 - Facebook

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.

Solution 8 - Facebook

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichardView Question on Stackoverflow
Solution 1 - FacebookAlexView Answer on Stackoverflow
Solution 2 - FacebookloungerdorkView Answer on Stackoverflow
Solution 3 - FacebooktypeoneerrorView Answer on Stackoverflow
Solution 4 - FacebookjanaView Answer on Stackoverflow
Solution 5 - FacebookRichardView Answer on Stackoverflow
Solution 6 - FacebookBen FlynnView Answer on Stackoverflow
Solution 7 - FacebookschungView Answer on Stackoverflow
Solution 8 - FacebookRoozbeh15View Answer on Stackoverflow