Question

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

Était-ce utile?

La solution

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!

Autres conseils

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);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top