Facebook获得好友ID

时间:2012-06-25 20:55:00

标签: android facebook

  

可能重复:
  Getting all Facebook friends using Graph API

我正在尝试在Android上获取所有朋友的脸书ID。这是我使用的代码:

public static List<String> getFaceBookFriendsIDs() {

        List<String> friendsList = null;
        try {
            JSONObject result = new JSONObject(ParseFacebookUtils.getFacebook().request("me/friends"));
            JSONArray friendsArray = result.getJSONArray("data");

            friendsList = new ArrayList<String>();
            for (int i = 0; i < friendsArray.length(); i++) {
                friendsList.add(friendsArray.getJSONObject(i).getString("id"));
            }
        } 
        catch (MalformedURLException e) {
            e.printStackTrace();

        } 
        catch (JSONException e) {
            e.printStackTrace();

        } 
        catch (IOException e) {
            e.printStackTrace();

        }

        return friendsList;

    }

然而,列表的含义与我拥有的朋友数量不同。这是正常的,还是我做错了什么?

1 个答案:

答案 0 :(得分:-1)

使用RestFB API! see here 使一切变得更容易并产生(可能)一些开销,但仍然,它可能更容易。