Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

android - Get friend list facebook 3.0

I'm trying to obtain my friend list from facebook using new SDK(3.0). I'm facing problems related to what kind of params I need to insert in a Bundle and how to use newMyFriendRequest and GraphAPI.

I didn't find on facebook documentation a place about what kind of field does we have to use. Based on GraphExplorer I insert in my Bundle the key "fields" with this string "id,name,friend" as a value. The code below shows what I'm doing right now. After I get My picture and name I execute newMyFriendRequest. I believe it uses GraphAPI by default.

I've seen here on StackOverflow some posts related:

How to send a FQL query with the new Android SDK

Facebook Android SDK request parameters: where find documentation?

It helps me little and I don't want to use FQL. For response II'm receiving this JSON like an answer:

{Response:  responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 100, errorType: FacebookApiException, errorMessage: Unsupported operation}, isFromCache:false}

Notice I'm very new in Facebook SDK for Android.

private void onSessionStateChange(final Session session, SessionState sessionState, Exception ex){
    if(session != null && session.isOpened()){
        getUserData(session);
    }
}

private void getUserData(final Session session){
    Request request = Request.newMeRequest(session, 
        new Request.GraphUserCallback() {
        @Override
        public void onCompleted(GraphUser user, Response response) {
            if(user != null && session == Session.getActiveSession()){
                pictureView.setProfileId(user.getId());
                userName.setText(user.getName());
                getFriends();

            }
            if(response.getError() !=null){

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

private void getFriends(){
    Session activeSession = Session.getActiveSession();
    if(activeSession.getState().isOpened()){
        Request friendRequest = Request.newMyFriendsRequest(activeSession, 
            new GraphUserListCallback(){
                @Override
                public void onCompleted(List<GraphUser> users,
                        Response response) {
                    Log.i("INFO", response.toString());

                }
        });
        Bundle params = new Bundle();
        params.putString("fields", "id,name,friends");
        friendRequest.setParameters(params);
        friendRequest.executeAsync();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In getFriends() method, change this line:

params.putString("fields", "id,name,friends");

by

params.putString("fields", "id, name, picture");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...