已经验证了同一个应用程序的FB好友列表

时间:2014-04-07 06:39:19

标签: android facebook facebook-graph-api android-facebook

我正在使用Facebook图表api:

我需要获取已经通过AUTHENTICATED MY APPLICATION的朋友列表。

第一个问题: 这是可能的吗?

如果是,请指导我应该从哪里开始搜索。

我已经经历了类似问题的SO而且在我的情况下都不合适。

请帮忙! 谢谢。

1 个答案:

答案 0 :(得分:2)

Facebook API提供了一个布尔字段,可以帮助您使用已安装的应用程序过滤用户的朋友。您需要请求用户的好友列表并设置必填字段以包含"已安装"布尔值。以下代码段可能会帮助您解决问题。

private void requestMyAppFacebookFriendsWithAppInstalled(Session session) {

            Request friendsRequest = createRequest(session);
            friendsRequest.setCallback(new Request.Callback() 
                {
            @Override
            public void onCompleted(Response response) 
            {
            //SetUpList
            List<GraphUser> friends = getResults(response);
            GraphUser user;
            friendsList=new ArrayList<ACT_friendsListPicker.FB_FriendsListStructure>();
            boolean installed = false;
             if(friends!=null)
             {
              for(int count=0;count<friends.size();count++)
              {
                user = friends.get(count);
                if(user.getProperty("installed") != null)
                {
            installed = (Boolean) user.getProperty("installed");
            Log.i("frndsPickerAppInstalled? YES ","user: "+user.getInnerJSONObject());
                }
             }}}});



    private Request createRequest(Session session) {
            Request request = Request.newGraphPathRequest(session, "me/friends", null);

            Set<String> fields = new HashSet<String>();
            String[] requiredFields = new String[] { "id", "name", "picture","hometown",
            "installed" };
            fields.addAll(Arrays.asList(requiredFields));

            Bundle parameters = request.getParameters();
            parameters.putString("fields", TextUtils.join(",", fields));
            request.setParameters(parameters);

            return request;
        }



private class FB_FriendsListStructure
    {
        String Name,ID,ImageUrl;
        boolean selected;
    }


private List<GraphUser> getResults(Response response) throws NullPointerException
    {
        try{
            GraphMultiResult multiResult = response
                    .getGraphObjectAs(GraphMultiResult.class);
            GraphObjectList<GraphObject> data = multiResult.getData();
            return data.castToListOf(GraphUser.class);
        }
        catch(NullPointerException e)
        {
           return null;
               //at times the flow enters this catch block. I could not figure out the reason for this.
        }
    }