简体   繁体   中英

Android Facebook SDK How to get all friends list who installed my app

i succeeded to get friends who installed my app BUT i have a case which is that some friends who already installed my app ,I could not find them when i request to get the list of friends who installed my app . i guess the are not listed due to their Facebook privacy . is it right ? or what is the problem ?

Here is my request code

        public void find_facebook_friends()
{            

    GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback()
    {
        @Override
        public void onCompleted(JSONObject object, GraphResponse response)
        {

            JSONObject json = response.getJSONObject();

            try
            {
                String friend_name = null;
                String friend_id = null;
                if (json != null)
                {
                    String js = json.toString();
                    String res = response.toString();
                    JSONObject c = response.getJSONObject();
                    JSONObject myfriends = null;

                    try
                    {
                        myfriends = c.getJSONObject("friends");
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                    }

                    if (myfriends != null)
                    {
                        JSONArray mydata = myfriends.getJSONArray("data");
                        facebookfriends_namesArray = null;
                        facebookfriends_idArray = null;
                        for (int i = 0; i < mydata.length(); i++)
                        {

                            JSONObject jsonobject = mydata.getJSONObject(i);
                            friend_id = jsonobject.getString("id");
                            friend_name = jsonobject.getString("name");
                        }
                    }

                }
            }
            catch (JSONException e)
            {
                e.printStackTrace();

            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,email,picture,gender,friends, birthday,first_name,last_name,locale,timezone,updated_time,verified,friendlists");
  request.setParameters(parameters);
    request.executeAsync();
}

Try this. Please make sure your read permissions include user_friends as follows

loginButton.setReadPermissions("email", "public_profile","user_friends");
        loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.d(TAG, "facebook:onSuccess:" + loginResult);

            }

            @Override
            public void onCancel() {
                Log.d(TAG, "facebook:onCancel");
            }

            @Override
            public void onError(FacebookException error) {
                Log.d(TAG, "facebook:onError", error);
            }
        });

Then get friends like this

 GraphRequest request = GraphRequest.newMyFriendsRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
                                    @Override
                                    public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) {

}
});

or by get request

String urll="https://graph.facebook.com/v2.7/me/friends?access_token="+ user accesstoken;

Refer:- https://coderzpassion.com/android-using-facebook-login-application-using-latest-facebook-sdk/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM