void pointer
void pointer

Reputation: 578

Get friend list from facebook using newMyFriendsRequest method - Android

In my Android application I want to display Facebook friend list with their information. For retrieving friend'd data I used following code :-

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (state.isOpened()) {
        Log.i(TAG, "Logged in...");
        Request friendRequest = Request.newMyFriendsRequest(session, 
                new GraphUserListCallback(){
            @Override
            public void onCompleted(List<GraphUser> users,
                    Response response) {
                Log.i("INFO", response.toString());
                GraphObject graphObject = response.getGraphObject();
                if (graphObject != null) {
                    JSONObject jsonObject = graphObject.getInnerJSONObject();
                    try {
                        JSONArray array = jsonObject.getJSONArray("data");
                        //code to store data
                    } catch (JSONException e) {

                        e.printStackTrace();
                    }
                }

            }
        });
        Bundle params = new Bundle();
        params.putString("fields", "id, name , picture");
        friendRequest.setParameters(params);
        friendRequest.executeAsync();


    } else if (state.isClosed()) {
        Log.i(TAG, "Logged out...");
    }
}

But when I run the code and print log message as per this line from code :-

Log.i("INFO", response.toString());

I got following log message :-

INFO: {Response:  responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[],"summary":{"total_count":1029}}}, error: null, isFromCache:false}

which states correct facebook friend "1029" but actual data is null "data":[]. How to retrieve correct data? Kindly correct me.

EDIT1

Now it is confirmed that we can get only get friend list who have installed same app.I used same code as above mention, only single line of change :-

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

I want to access friends birthday as well.I put all necessary permissions for same as follows

"read_friendlists","friends_birthday","read_stream", "offline_access"

But response only contains id and name but not birthdate.

Kindly suggest needful.

Kindly provide solution.

Upvotes: 0

Views: 2020

Answers (2)

andyrandy
andyrandy

Reputation: 73984

https://developers.facebook.com/docs/apps/changelog

Apps created after April 30, 2014 will only be able to get friends who authorized your App too. Apps created before that date will be upgraded to v2.0 after April 2015.

There is a very detailed answer that covers everything you need to know in this thread: https://stackoverflow.com/a/23417628/757508

Upvotes: 4

J.Vassallo
J.Vassallo

Reputation: 2292

Unfortunately since March 2014 or so , facebook sdk restricted the friend list to friends that have your app installed. So basically it will return the friend list null if no user has your app installed.

Upvotes: 2

Related Questions