0

i'm create some code to get friends list using graph api but didn't find friends list.i just got total number of friends only.

Code:-

 LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_friends", "email"));
        LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(LoginResult loginResult) {
                        Log.e("Success1", "Success" + loginResult.getAccessToken().getToken());
                        GraphRequest request = GraphRequest.newMeRequest(
                                loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                                    @Override
                                    public void onCompleted(JSONObject json, GraphResponse response) {
                                        progressDialog.dismiss();

                                        if (response.getError() != null) {
                                            // handle error
                                            Log.e("getError", "getError");
                                        } else {
                                            Log.e("Success2", "Success");
                                            try {
                                                String jsonresult = String.valueOf(json);
                                                Log.e("JSON", "" + jsonresult);

                                                new GraphRequest(
                                                        AccessToken.getCurrentAccessToken(),
                                                            "/" + json.getString("id") + "/friends",
                                                        null,
                                                        HttpMethod.GET,
                                                        new GraphRequest.Callback() {
                                                            public void onCompleted(GraphResponse response) {
                                                                Log.e("response", "" + response);
                                                            }
                                                        }
                                                ).executeAsync();
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                                Log.e("JSONException", "" + e.getMessage());
                                            }
                                        }
                                    }

                                });
                        Bundle parameters = new Bundle();
                        parameters.putString("fields", "id, first_name, last_name, email,gender, birthday, location,friends"); // Parámetros que pedimos a facebook
                        request.setParameters(parameters);
                        request.executeAsync();
                    }

                    @Override
                    public void onCancel() {
                        Log.e("cancel", "On cancel");
                        progressDialog.dismiss();
                    }

                    @Override
                    public void onError(FacebookException error) {
                        Log.e("Error", error.toString());
                        progressDialog.dismiss();
                    }
                });

OutPut:-

{"data":[],"summary":{"total_count":475}}, error: null}
ckpatel
  • 1,926
  • 4
  • 18
  • 34

1 Answers1

1

After the update of Facebook Graph API 2.0 you will be able to get your friends only who uses your app.

With Graph API v2.0 and above, calls to /me/friends return only the friends who also use your app. These friends must have also granted the user_friends permission. In the cases where you want to let people tag their friends in stories published by your app, you can use the Taggable Friends API.

Check this for more info https://developers.facebook.com/docs/apps/faq#faq_1694316010830088

Kavin Varnan
  • 1,989
  • 18
  • 23