Android : 如何获取使用 App FB SDK 2.4 的人的所有朋友 a

Android : How to get all friend a of person using App FB SDK 2.4

我创建了一个应用程序 facebook 并在应用程序上使用创建按钮登录 (android)。 我想当一个人打开应用程序并登录时,我可以得到 they.But 的所有朋友,我尝试了一些方法但没有(return Null)。请给我一个建议。 谢谢大家! 这是我的代码:

private FacebookCallback<LoginResult> mCallback = new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        AccessToken accessToken = loginResult.getAccessToken();
        LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("user_friend","user_location", "user_birthday", "user_likes","user_photo"));
                new GraphRequest(
                        AccessToken.getCurrentAccessToken(),
                        "/me/taggable_friends",
                        null,
                        HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response) {
                            Toast.makeText(getActivity(), response.getJSONObject() + "", Toast.LENGTH_LONG).show();
                            }
                        }
                ).executeAsync();
        }
    @Override
    public void onCancel() {

    }

    @Override
    public void onError(FacebookException e) {

    }
};

你应该阅读这篇文章,

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

/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/me/friends",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

权限

需要具有 user_friends 权限的用户访问令牌才能查看当前人的好友。 这只会 return 任何使用过(通过 Facebook 登录)发出请求的应用程序的朋友。 如果此人的朋友拒绝 user_friends 许可,则该朋友将不会显示在此人的朋友列表中。

修饰符

你可以在边上追加另一个人的id来判断这个人是否是根节点用户的朋友:

/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{user-id-a}/friends/{user-id-b}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

如果在上述请求中用户a 是用户b 的好友,则响应将包含用户b 的用户对象。如果他们不是朋友,它将 return 一个空数据集。