使用 Facebook 图 api 上的特定用户 ID 访问 public 信息

Accessing public information using a specific userID on facebook graph api

有人登录了我的应用程序。我需要显示一些可能不在此人的朋友列表中的人的个人资料。这可能吗,还是隐私问题。一个人的 "public profile" 应该是可以访问的吧?

我试图获取名字、头像和性别

Bundle parameters = new Bundle();
parameters.putString("fields", "first_name,gender");

try {
    new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/" + user.getUserID(),
            parameters,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {
                    JSONObject facebookResponse = response.getJSONObject();
                    try {
                        final String first_name = facebookResponse.getString("first_name");
                        final String gender = facebookResponse.getString("gender");

                        Bundle params = new Bundle();
                        params.putBoolean("redirect", false);
                        params.putString("type", "square");
                        params.putInt("width", 200);
                        params.putInt("height", 200);

                        new GraphRequest(
                                AccessToken.getCurrentAccessToken(),
                                "/" + user.getUserID() + "/picture",
                                params,
                                HttpMethod.GET,
                                new GraphRequest.Callback() {
                                    public void onCompleted(GraphResponse response) {
                                        JSONObject facebookResponse = response.getJSONObject();
                                        try {
                                            JSONObject data = facebookResponse.getJSONObject("data");
                                            String url = data.getString("url");

                                            Name.setText(first_name);
                                            Gender.setText(gender);
                                            mNetworkImageView.setImageUrl(url, mImageLoader);

                                            facebookResponseListener.updatedUserObject(first_name, url, gender, pos);

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

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

} catch (Exception uee) {
    uee.printStackTrace();
}

所有这些都在 getView() if 列表视图中(这是我显示配置文件的地方)。在测试时,我得到了登录人的朋友的所有信息,但是非朋友缺少响应对象中的 "gender" 属性 。仅返回名称和用户 ID。

文档里都有解释(https://developers.facebook.com/docs/facebook-login/permissions):

gender & locale can only be accessed if:

The person queried is the person using the app.

The person queried is using the app, and is a friend of the person using the app.

The person queried is using the app, is not a friend of the person using the app, but the app includes either an app access token or an appsecret_proof argument with the call.