Facebook 'Friends.getAppUsers' using Graph API

青春壹個敷衍的年華 提交于 2019-11-26 19:19:07
Alex

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:

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!

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.

jana

Old REST API:

$facebook->api_client->friends_getAppUsers();

New Graph API:

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

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.

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

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.

Roozbeh15

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!