繁体   English   中英

Android Facebook SDK 如何获取安装我的应用程序的所有好友列表

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

我成功地找到了安装我的应用程序的朋友,我有一个案例,即一些已经安装了我的应用程序的朋友,当我请求获取安装我的应用程序的朋友列表时找不到他们。 我猜由于他们的 Facebook 隐私没有列出。 是吗? 或者有什么问题?

这是我的请求代码

        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如下

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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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