无法获取facebook sdk示例中的朋友列表的所有字段,并且在Friend Picker Sample中只获取id,在android中命名

时间:2013-12-20 12:02:17

标签: android facebook friend

我正在开发facebok示例演示,以获取登录用户的所有朋友列表。 我成功运行了Friend Picker Sample,但是getstuck提取朋友的所有细节,比如email,first_name,last_name等。我只得到id,name。

如果有人有意,请回复。

这是我的代码: -

public void getFriends(Properties properties, final OnFriendsRequestListener onFriendsRequestListener)
    {
        // if we are logged in
        if (isLogin())
        {
            // move these params to method call parameters
            Session session = getOpenSession();
            Bundle bundle = null;
            if (properties != null)
            {
                bundle = properties.getBundle();

            }
            Request request = new Request(session, "me/friends", bundle, HttpMethod.GET, new Request.Callback()
            {
                @Override
                public void onCompleted(Response response)
                {
                    List<GraphUser> graphUsers = typedListFromResponse(response, GraphUser.class);

                    FacebookRequestError error = response.getError();
                    if (error != null)
                    {
                        // log
                        logError("failed to get friends", error.getException());

                        // callback with 'exception'
                        if (onFriendsRequestListener != null)
                        {
                            onFriendsRequestListener.onException(error.getException());
                        }
                    }
                    else
                    {
                        // callback with 'complete'
                        if (onFriendsRequestListener != null)
                        {
                            List<Profile> friends = new ArrayList<Profile>(graphUsers.size());
                            for (GraphUser graphUser: graphUsers)
                            {

                                friends.add(Profile.create(graphUser));
                            }
                            onFriendsRequestListener.onComplete(friends);
                        }
                    }

                }
            });

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

            // callback with 'thinking'
            if (onFriendsRequestListener != null)
            {
                onFriendsRequestListener.onThinking();
            }
        }
        else
        {
            String reason = Errors.getError(ErrorMsg.LOGIN);
            logError(reason, null);

            // callback with 'fail' due to not being loged
            if (onFriendsRequestListener != null)
            {
                onFriendsRequestListener.onFail(reason);
            }
        }
    }

提前致谢...

1 个答案:

答案 0 :(得分:2)

经过一段时间的努力,我尝试了一些方法,最后找到了解决方案。

public void getFriendsList() {
        Bundle bundle=new Bundle();
        bundle.putString("fields","id,name,first_name,last_name,email,picture,gender,birthday,work");
        mAsyncRunner.request("me/friends",bundle,friendsRequsetListener,null); 

    }


RequestListener friendsRequsetListener =new RequestListener() {

        @Override
        public void onMalformedURLException(MalformedURLException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onIOException(IOException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onComplete(String response, Object state) {
            // TODO Auto-generated method stub
            String json = response;
            try {
                Log.e("Response","========>"+json);

                    }
            catch(Exception e){

            }
        }
    };

我希望这会对别人有所帮助。谢谢!