0
votes

I have this snippet

  AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
                    Bundle bundle = new Bundle();
                    bundle.putString("fields", "birthday");
                    mAsyncRunner.request("me/friends", bundle, new FriendListRequestListener());

and it works somehow, I mean I can read the ids from all my friends. But in I want to read everything how can I do that ?

    String _error = null;

        JSONObject json = Util.parseJson(response);
        final JSONArray friends = json.getJSONArray("data");

        for (int i = 0; i < friends.length(); i++) {
            Log.v("id:", "id= "+friends.get(i).toString());
         }

What should I do to get info about my friends and to read that info

I guess this is the key, this is from the example I found and it works fine

bundle.putString("fields", "birthday");

but when I put for example, doesn't works

bundle.putString("fields", "friends_relationships");

-----------------EDIT 1-------------------------

code for permissions

    mFacebook.authorize(Example.this, new String[] {"offline_access", "user_interests", "friends_interests","friends_relationships","friends_relationship_details"},new DialogListener() {
        @Override
        public void onComplete(Bundle values) {}

        @Override
        public void onFacebookError(FacebookError error) {}

        @Override
        public void onError(DialogError e) {}

        @Override
        public void onCancel() {}
   });

-------------- EDIT 2 --------------

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

4

4 Answers

1
votes

Graph API is the smart choice in most cases. To retrieve your friend information you need to collect some extended permissions from the user first. Then you can retrieve a lot more information other than the basic ones.

Following is a list of extended permissions related to friends different kind of information

friends_about_me        
friends_activities      
friends_birthday
friends_checkins        
friends_education_history       
friends_events
friends_games_activity      
friends_groups      
friends_hometown
friends_interests       
friends_likes       
friends_location
friends_notes       
friends_online_presence     
friends_photo_video_tags 
friends_photos      
friends_relationship_details        
friends_relationships
friends_religion_politics       
friends_status      
friends_subscriptions
friends_videos      
friends_website     
friends_work_history

facebook.authorize(this, new String[] {"offline_access", "user_interests", "friends_interests"},

Edit :-

If your app needs more than this basic information to function, you must request specific permissions from the user. This is accomplished by passing String[] of permissions to the authorize method. The following example shows how to ask for access to user's email address, get extended access token and check-in user at a place:

facebook.authorize(this, new String[] { "email", "publish_checkins" },

      new DialogListener() {
           @Override
           public void onComplete(Bundle values) {}

           @Override
           public void onFacebookError(FacebookError error) {}

           @Override
           public void onError(DialogError e) {}

           @Override
           public void onCancel() {}
      }
);

Look at here for more details.

Edit :-

 mAsyncRunner.request("me/friends?fields=id,name,birthday,relationship_status", new FriendListRequestListener());

JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");

for(int i=0;i<friends.length();i++)
{
    JSONObject object = friends.getJSONObject(i);
    Log.i("------------------ Id",object.getString("id"));
    Log.i("------------------ Name",object.getString("name"));
    Log.i("------------------ RelationShip",object.getString("relationship_status"));
 }
0
votes

There are separate permissions for your friends relationships. Check out the permissions documentation.

You'll want to request -

  • friends_relationships
  • friends_relationship_details
0
votes

This is now longer possible as of May 2015 when the v1.0 facebook Graph API got deprecated.

-1
votes

try this :

 Bundle params = new Bundle();
 params.putString("fields", "name, picture, location");
    mAsyncFacebook.request("me/friends",params, new RequestListener(){
        @Override
        public void onComplete(String response, Object object) {
            JSONObject jsonObject = null;
            try {
                jsonObject = new JSONObject(response);
            } catch (JSONException e) {
                Log.d(TAG,"Exception :"+e);
            }

        }
   }

to know about the keys see this link : https://developers.facebook.com/docs/authentication/permissions/