0

I'm developing new android app which uses facebook sdk. I want to fetch users friends list, I'm doing it like that:

Request request = Request.newMyFriendsRequest(
                        Session.getActiveSession(),
                        new Request.GraphUserListCallback() {
                            public void onCompleted(List<GraphUser> paramAnonymousList,
                                    Response paramAnonymousResponse) {
                                Toast.makeText(getApplicationContext(),
                                        paramAnonymousList.toString(),
                                        Toast.LENGTH_SHORT).show();
                                Log.e(TAG, paramAnonymousList.toString()
                                        + paramAnonymousResponse.toString());
                            }
                        });
                request.executeAsync();

However when I run app I'm getting something like that:

GraphObjectList{itemType=GraphUser, state=[]}{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}

I tried to run this code inside app which is not in development mode and it's working fine - i'm able to fetch user's data. What can be the cause of response code 200. According to that: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0 response code 200 belong to facebook permission errors. But to fetch user's friends list I don't have to provide any specific permissions, so what can be the cause of this response?

Thanks in advance

Androider
  • 435
  • 1
  • 9
  • 22

2 Answers2

2

HTTP 200 means that your request is OK.

The real issue is Facebook API v2.0. Apps cannot retrieve the full list of friends for a user, only friends already using the application. Even if you application is still in v1.0, users who first logged in after May 1st are getting v2.0 behaviour.

Reference: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends

Cheers!

edgebal
  • 336
  • 1
  • 7
  • Thanks for answer but just to be 100% sure - there is not any solution to retrieve full contacts list? Even if I asked for the specified permission? I saw app on android that can get the full contacts list – Androider May 14 '14 at 09:54
  • As I told you, if you gave permissions to that application before May 1st, that application was (and still is until May 2015) able to retrieve your the full list of your friends. But people giving permissions to applications after that date are getting the new v2.0 limitation to the list of friends who are already using the app. The permission is to allow access to that limited list (`user_friends` it's not already implictly asked on Basic Permissions). – edgebal May 14 '14 at 20:52
  • to sum up facebook sucks ;) – Androider May 15 '14 at 18:28
0

I have done in this way and works fine perfectly in Facebook SDK 4.18.0

public class SignIn extends AppCompatActivity {

    CallbackManager callbackManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //before set conteview
        FacebookSdk.sdkInitialize(getApplicationContext());
        //  AppEventsLogger.activateApp(this);
        callbackManager = CallbackManager.Factory.create();
        setContentView(R.layout.activity_signin);

        LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);

        loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));

        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                GraphRequest graphRequest=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {

                        Log.d("Graph Response",graphResponse.toString());

                        String myCustomizedResponse = graphResponse.getJSONObject().toString();

                        Log.d("Ketan_Ramani",graphResponse.getJSONObject().toString());

                        try {
                            JSONObject obj = new JSONObject(myCustomizedResponse);

                            String id = obj.getString("id");
                            String first_name = obj.getString("first_name");
                            String last_name = obj.getString("last_name");
                            String email = obj.getString("email");

                            Log.d("Id",id);
                            Log.d("FirstName",first_name);
                            Log.d("LastName",last_name);
                            Log.d("Email",email);

                        } catch (JSONException e) {
                            Utils.hide_dialog();

                            e.printStackTrace();
                        }
                    }
                });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,name,first_name,last_name,email");
                graphRequest.setParameters(parameters);
                graphRequest.executeAsync();
            }

            @Override
            public void onCancel() {
                // App code
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
}
pacholik
  • 8,607
  • 9
  • 43
  • 55
Ketan Ramani
  • 4,874
  • 37
  • 42