Search code examples
androidfacebookfacebook-friends

trying to retrieve FriendList from facebook returns null


I am a newbie in Android. I am trying to retrieve my FriendsList from Facebook. I am not getting the friendlist as the data I get from the json array is always null. I have read about setting the permissions to retrieve the friendslist but I don't understand where and how to set it. Can anyone help me with this issue. please instruct me step by step as I am a beginner. My codes are as follows:

I have added the missing permission as follows:

 mFacebook.authorize(MainActivity.this, new String[] { "user_friends" },
                    new LoginDialogListener());

but still the result is null.

MainActivity.java

   public Facebook mFacebook = new Facebook(mAPP_ID);
   public void getme()
     {
        // TODO Auto-generated method stub
       Session activeSession = mFacebook.getSession();
       if(activeSession.getState().isOpened())
         {
         final AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
         mAsyncRunner.request("me/friends", new FriendListRequestListener());
         }


      }      

FriendsListRequestListener.java

     public class FriendListRequestListener implements RequestListener {

@Override
public void onComplete(String response, Object state) {
    // TODO Auto-generated method stub
    try
    {
    JSONObject json = Util.parseJson(response);
    final JSONArray friends = json.getJSONArray("data");
    Log.i("jjj",""+friends);

    }
    catch(JSONException exception)
    {
        Log.e("err", ""+exception.toString());
    }
}

@Override
public void onIOException(IOException e, Object state) {
    // TODO Auto-generated method stub

}

@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
    // TODO Auto-generated method stub

}

@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
    // TODO Auto-generated method stub

}

@Override
public void onFacebookError(FacebookError e, Object state) {
    // TODO Auto-generated method stub

}

 }

Solution

  • Since v2.0 of the Graph API, /me/friends only returns friends who authorized your App too, for privacy reasons.

    More information: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app