Facebook,在android中获取超过id和firendlist的名称

时间:2014-01-11 18:53:42

标签: android facebook

所以bassicaly,我用它来登录:

authButton.setReadPermissions(Arrays.asList("basic_info","email","friends_about_me"));
    // session state call back event
    authButton.setSessionStatusCallback(new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) { 
            if (session.isOpened()) {
                Log.i(TAG,"Access Token"+ session.getAccessToken());
                Request.newMeRequest(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user,Response response) {
                        if (user != null) {
                            Log.i(TAG,"User ID "+ user.getId());
                            Log.i(TAG,"Email "+ user.asMap().get("email"));
                            Log.d(TAG, "gender = " + user.getProperty("gender"));

                        }
                    }
                }).executeAsync();
            }
        }
    });

我添加了friends_about_me,因为我想在朋友列表和其他活动中获取人物的性别,这是我确定朋友列表的那个:

private void requestFacebookFriends(final Session session) {
    Request friendrequest = Request.newMyFriendsRequest(session,
            new Request.GraphUserListCallback() {

        @Override
        public void onCompleted(List<GraphUser> users,
                Response response) {
            if (session == Session.getActiveSession()) {
                friendlist = new ArrayList<Friends>();
                if (users != null) {
                    for (GraphUser user : users) {
                        Log.d(TAG, "gender = " + user.getProperty("gender"));
                        Log.d(TAG, "gender = " + user.asMap().get("gender"));
                    }
                }
            }
        }
    });
    friendrequest.executeAsync();
}

因此,当我尝试在登录中执行Request.newMeRequest()时,我可以获取MY性别,但它不能与我的朋友列表一起使用,在日志中,所有性别返回null。 我错过了许可吗?或者做到这一点的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要在朋友请求中请求其他字段,例如:

Request friendrequest = Request.newMyFriendsRequest(...);

Bundle params = friendrequest.getParameters();
params.putString("fields", "name,id,gender");
friendrequest.setParameters(params);
friendrequest.executeAsync();