Unable get all fields of friend list in facebook sdk sample and In Friend Picker Sample getting only id,name in android

做~自己de王妃 提交于 2020-01-05 03:10:16

问题


I am developing facebok sample demo for get all friend list of login user. I am running Friend Picker Sample successfully,But getstuck to extract all the details of friends like email,first_name,last_name etc.I am getting only id,name.

If anyone have idea please reply.

Here is mycode:-

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);
            }
        }
    }

Thanks in advance...


回答1:


After very sturggle i try some methods and finally found solution.

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){

            }
        }
    };

I hope this will help others. Thanks!!



来源:https://stackoverflow.com/questions/20703238/unable-get-all-fields-of-friend-list-in-facebook-sdk-sample-and-in-friend-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!