FB friends list who have already authenticated the same application

孤人 提交于 2020-01-03 06:06:27

问题


I am working with Facebook graph api:

I need to get the list of friends who have already AUTHENTICATED MY APPLICATION.

First question: IS THIS POSSIBLE?

and if yes please guide me where should I start searching for it.

I have already gone through SO for similar question and none suits in my case.

Please help! Thank you.


回答1:


Facebook API provides a boolean field that can help you filter the User's friends with your application Installed. You need to Make a request for User's Friends List and set the required fields to include the "installed" boolean. The following code snippet may help you out.

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.
        }
    }


来源:https://stackoverflow.com/questions/22905210/fb-friends-list-who-have-already-authenticated-the-same-application

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