Search code examples
androidfacebookfacebook-graph-apifacebook-friends

Facebook Friends Request - Missing Friends


I am requesting to get user friends from an Android App that I am developing. As from Facebook Api V2.0 I know that I should get only user friends that have already logged in through my App. However, although I know certain friends of a user have logged In through my App they do not appear in Facebook Request Response when requesting friends of that user. For example I get back 40 friends rather than 50+.

Has anyone experienced this behavior before? I already deleted app from few users to re-authorized it through login but I haven't see any change in the behavior.

Here is the code I'm using:

new Request(ParseFacebookUtils.getSession(),"me/friends", null, null, new Request.Callback(){

        @Override
        public void onCompleted(Response response) {

            if (response == null){ 
                return;
            }
            else if (response.getError() != null){
                response.getError().getException().printStackTrace();
                return;
            }

            GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);

            List<GraphObject> fbInList = result.getData();

            if (fbInList != null && !fbInList.isEmpty()){

                for (GraphObject user : fbInList) {

                    JSONObject jsonUser = user.getInnerJSONObject(); // The Facebook User
                    System.out.println("name: " + jsonUser.optString("name"));
                }       
            }
        }
    }).executeAsync();

Solution

  • I've found what was the problem. When I updated to the latest Facebook SDK, Facebook was returning only 25 friends. I needed to use paging or add a limit to my Friend Request. On previous SDK I didn't need to.

    Adding limit:

    Bundle params = new Bundle();
    params.putString("limit", "50"); // Up to 5000?
    friendRequest.setParameters(params);
    

    Relevant Stack Overflow Questions:

    Facebook graph API 'friends' request now only returning 25 friends per page? What's going on?

    newMyFriendsRequest Facebook returns only 25 friends

    Useful Facebook link for paging:

    https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging