Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all friends name, id, birthday, location, etc.. from facebook API in android? [duplicate]

Possible Duplicate:
How to get friend's birthday list using facebook api?

I want to display the list that contain information like name, id, birthday, location from facebook in android application.

I am beat successful in work though the following code I have get the friend's name and ID

           Bundle parameters = new Bundle();
    mAccessToken = facebook.getAccessToken();

    try {

        parameters.putString("format", "json");
        parameters.putString(TOKEN, mAccessToken);

        String url = "https://graph.facebook.com/me/friends";
        String response = Util.openUrl(url, "GET", parameters);
        JSONObject obj = Util.parseJson(response);

        Log.i("json Response", obj.toString());
        JSONArray array = obj.optJSONArray("data");

        if (array != null) {
            for (int i = 0; i < array.length(); i++) {
                String name = array.getJSONObject(i).getString("name");

                String id = array.getJSONObject(i).getString("id");

                Log.i(name,id);
            }
        } 

                ............
                ............

but not get birthday, location, etc fields in json response. what is mistake?

like image 528
milind Avatar asked Jan 10 '11 10:01

milind


2 Answers

Use the FQL language to get very quickly all the information you want:

$this->api->api(array('method'=>'fql.query','query'=>"SELECT uid,name,first_name,middle_name,last_name,pic_square,hometown_location,current_location,profile_url,email,website FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"));

For a list of all the tables with their corresponding column names I refer to: Facebook FQL Reference

like image 181
Daan Avatar answered Oct 28 '22 15:10

Daan


When I wanted to get a list of my friends, and filter on just their name and website, this worked for me: https://graph.facebook.com/me/friends?fields=name,website&access_token=someCrazyLongRandomlyGeneratedString

Seems like you should be doing that, and you would just replace 'name,website' with 'name,id,birthday,location' or whatever you'd like to get in the response from the list of fields contained in the User object: http://developers.facebook.com/docs/reference/api/user/. I believe id is automatically included with the response, so you don't have to actually include it in the request.

like image 35
susanm74 Avatar answered Oct 28 '22 16:10

susanm74