Facebook API friends who use same app android

谁说胖子不能爱 提交于 2019-12-01 06:55:33

问题


I have a code the retrieves all friends from facebook api , but i would like to get only the facebook friends who use application. i tried fb.request("me/friends?fields=installed"); but never worked do i need extra permission ?

Heres my code:

jsonUser = fb.request("me/friends");
friendObj = Util.parseJson(jsonUser);

friendArray = friendObj.getJSONArray("data");

friendlist = new ArrayList<String[][]>();
String[][] friendsToList = new String[1][2];
int friendCount = 0;
String fId, fNm;
JSONObject friend;

for (int i = 0;i<friendArray.length();i++){
    //Get a JSONObject from the JSONArray
    friend = friendArray.getJSONObject(i);
    //Extract the strings from the JSONObject
    friendsToList[0][0] = friend.getString("id");
    friendsToList[0][1] = friend.getString("name");
    friendlist.add(friendsToList);
    //Set the values to our arrays
    Log.e("Tester",""+ friendsToList[0][0]+" "+ friendsToList[0][1]);
    friendCount ++;
}

回答1:


Solved By

AsyncTask.execute(new Runnable() {
            public void run() {
                try{
                    String fql = "SELECT uid, name FROM user WHERE is_app_user  AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
                    Bundle parameters = new Bundle();

                    parameters.putString("query", fql);
                    parameters.putString("method", "fql.query");
                    parameters.putString("access_token",  fb.getAccessToken());
                    String Response = fb.request(parameters);
                    JSONArray json = new JSONArray(Response);
                    list = new ArrayList<String[][]>();
                    String[][] friendsToList = new String[1][2];
                    SpinnerList = new ArrayList<String>();
                    String TempToSpinnerList=new String();
                    for(int i = 0; i < json.length(); ++i){
                        friendsToList[0][0] = json.getJSONObject(i).getString("uid");
                        friendsToList[0][1] = json.getJSONObject(i).getString("name");
                        TempToSpinnerList= friendsToList[0][1];
                            list.add(friendsToList);
                            SpinnerList.add(TempToSpinnerList);
                            Log.e("Test"," "+friendsToList[0][1]+" "+friendsToList[0][0]);
                        }


来源:https://stackoverflow.com/questions/13853804/facebook-api-friends-who-use-same-app-android

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