-2

I want to fetch friends of friends from facebook but cannot achieve the same. I have followed this link(The one with 3 upvotes).I can get my friendlist.But whenever I try to access friends of a friend facebook is returning a strange result.Suppose A is a friend of B and B is a friend of C. I have installed my app on all devices of A,B AND C.When I run my app as user A,I get json response which contains Bs details.Then I again hit another url using Bs userid and this time I must get details of C.But facebook is returning details of A only.

Here are relevant codes:

The below asynctask is use to retrieve friend of an user:

Here I am hitting the url :https://graph.facebook.com/me/friends?access_token=USERS_ACCESS_TOKEN

public class GetFriendList extends AsyncTask<String,String,String>
        {   private ProgressDialog progressDialog;


        protected void onPreExecute() {
            super.onPreExecute();
            if (progressDialog == null) {
                progressDialog = createProgressDialog(MainActivity.this);
                progressDialog.show();
            } else {
                progressDialog.show();
            }


        }       

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub

            // contactList = new ArrayList<HashMap<String, String>>();



            //String urlforget="https://graph.facebook.com/"+mediaid+"/friends?access_token="+access_token;

            String urlforget="https://graph.facebook.com/me/friends?access_token="+access_token;
            System.out.println(urlforget);

            ServiceHandle sh = new ServiceHandle();

            String jsonStr = sh.makeServiceCall(urlforget, ServiceHandle.GET);
            // after getting  JSON string from the URL
            System.out.println(""+jsonStr);
            //Toast.makeText(getBaseContext(), "result:"+jsonStr, Toast.LENGTH_SHORT).show();

            try {

                if (jsonStr != null) 
                {
                    JSONObject jsonobj = new JSONObject(jsonStr);
                    // Getting JSON Array node




                    myfriendlist = jsonobj.getJSONArray("data");


                    // looping through All Contacts
                    for (int i = 0; i <myfriendlist.length(); i++) {
                        JSONObject c = myfriendlist.getJSONObject(i);

                        friendmediaid=c.getString("id");
                    }


                }


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




            return null;
        }//doInbacckground


        protected void onPostExecute(String file_url) { 

            progressDialog.dismiss();

            new GetFriendofFriendList(friendmediaid).execute();



        }//postexecute

        }//Asynctask

Next to retrieve friends from the id I got from the previous asynctask,I hit the url: "https://graph.facebook.com/"+fmediaid+"/friends?access_token="+access_token;

Asynctask:

 public class GetFriendofFriendList extends AsyncTask<String,String,String>
        {   private ProgressDialog progressDialog;
            String fmediaid,nurl;

        public GetFriendofFriendList(String mediaid,String nurl) {
            // TODO Auto-generated constructor stub
            this.fmediaid=mediaid;
            this.nurl=nurl;
        }


        protected void onPreExecute() {
            super.onPreExecute();
            if (progressDialog == null) {
                progressDialog = createProgressDialog(MainActivity.this);
                progressDialog.show();
            } else {
                progressDialog.show();
            }


        }       

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub

            // contactList = new ArrayList<HashMap<String, String>>();



            System.out.println("2nd async==>"+fmediaid);

            String urlforget="https://graph.facebook.com/"+fmediaid+"/friends?access_token="+access_token;

            //String urlforget="https://graph.facebook.com/me/friends?access_token="+access_token;
            System.out.println(urlforget);

            ServiceHandle sh = new ServiceHandle();

            String jsonStr = sh.makeServiceCall(urlforget, ServiceHandle.GET);
            // after getting  JSON string from the URL
            System.out.println("Friend of friend===>"+jsonStr);
            //Toast.makeText(getBaseContext(), "result:"+jsonStr, Toast.LENGTH_SHORT).show();



            return null;
        }//doInbacckground


        protected void onPostExecute(String file_url) { 

            progressDialog.dismiss();



        }//postexecute

        }//Asynctask

But the above asynctask is returning the profile from which I am using the app.(A as I mentioned above).

This is how I am generating access token:

 @Override
             public void call(Session session, SessionState state, Exception exception) {
                 if (session.isOpened()) {
                     Toast.makeText(MainActivity.this, session.getAccessToken(), Toast.LENGTH_LONG).show();
                     System.out.println(session.getAccessToken());
                     access_token=session.getAccessToken();

So what wrong I am doing??Why C is not showing up??I have taken all permissions and all 3 accounts have accepted "user_friends" permissions.

Community
  • 1
  • 1
kgandroid
  • 5,507
  • 5
  • 39
  • 69

1 Answers1

1

There is NO way you can get the friends of friends via the Graph API. This was never possible, and with the additional restrictions of Graph API v2.0, you even only the the user's friends which also use the app.

Furthermore, friends_* permissions have been deprecated since nearly one year now.

Tobi
  • 31,405
  • 8
  • 58
  • 90