Android Facebook SDK如何获取安装我的应用程序的所有朋友列表 [英] Android Facebook SDK How to get all friends list who installed my app

查看:70
本文介绍了Android Facebook SDK如何获取安装我的应用程序的所有朋友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地吸引了安装我的应用程序的朋友我遇到了一个案例,就是有些已经安装了我的应用程序的朋友,当我请求获取获得该列表的朋友的列表时,我找不到他们安装了我的应用程序.我想由于他们的Facebook隐私而未列出.这样对吗 ?还是有什么问题?

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 ?

这是我的请求代码

        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();
}

推荐答案

尝试一下.请确保您的读取权限包括 user_friends 如下

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);
            }
        });

然后得到这样的朋友

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

}
});

或通过获取请求

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

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

这篇关于Android Facebook SDK如何获取安装我的应用程序的所有朋友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆