Facebook 'Friends.getAppUsers' using Graph API

后端 未结 8 1771
盖世英雄少女心
盖世英雄少女心 2020-11-27 09:29

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.

相关标签:
8条回答
  • 2020-11-27 10:12

    Old REST API:

    $facebook->api_client->friends_getAppUsers();
    

    New Graph API:

    $facebook->api(array('method' => 'friends.getAppUsers'));
    
    0 讨论(0)
  • 2020-11-27 10:15

    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
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题