1

I am using social auth library for facebook integration. I am able to share/post text or images but i want to access my friend list.

Is it possible to access friend list via social auth in android?

Thanks in advance...

Jagdish
  • 2,418
  • 4
  • 25
  • 51
  • You have to add `read_friendlists` when You authorize to facebook. And then request with `/me/friendlists` – Gooziec Dec 17 '13 at 12:39
  • thanks for reply @Gooziec, Is there any example? – Jagdish Dec 17 '13 at 12:42
  • are you using sdk frovided by facebook? If so, then you can look up in their page https://developers.facebook.com/docs/graph-api/reference/user/friendlists – Gooziec Dec 17 '13 at 12:44
  • No, i am using social library http://code.google.com/p/socialauth-android/. – Jagdish Dec 17 '13 at 12:45

3 Answers3

2

I am using socialauth to get a list of friends in Facebook. They have more up to date information on their github page wiki. The code below is my adaptation of the examples in the wiki. I am getting Name, profile image and Facebook id.

in my Fragment:

public class Friends extends SherlockFragment {
 private static SocialAuthAdapter facebookAdapter;

I set up the adapter

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    facebookAdapter = new SocialAuthAdapter(new FacebookListener());

later in onCreateView I authorize the user

facebookAdapter.authorize(getSherlockActivity(), Provider.FACEBOOK);

Now I implement the first Listener (did they authorize)

private final class FacebookListener implements DialogListener 
    {
        public void onComplete(Bundle values) {

            Log.d("SocialAuth","Successful");
            facebookAdapter.getUserProfileAsync(new FacebookProfileDataListener());
            Toast.makeText(getSherlockActivity(),"Connection Successful",Toast.LENGTH_LONG).show();


        }

        @Override
        public void onError(SocialAuthError error) {
            Log.d("Custom-UI" , "Error");
        }

        public void onCancel() {
            Log.d("Custom-UI" , "Cancelled");
        }

        @Override
        public void onBack() {
            // TODO Auto-generated method stub

        }


    }

Now I get the profile

public final class FacebookProfileDataListener implements org.brickred.socialauth.android.SocialAuthListener<Profile>  {

        @Override
        public void onError(SocialAuthError arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onExecute(String arg0, Profile profile) {
            if (profile.getProviderId().equalsIgnoreCase(Provider.FACEBOOK.name())) {
                //store some of the profile information here
            }
            facebookAdapter.getContactListAsync(new FacebookContactDataListener());   
        }

    }

Now the Contact List

  public final class FacebookContactDataListener implements SocialAuthListener<List<Contact>> {

@Override
public void onError(SocialAuthError arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onExecute(String arg0, List<Contact> t) {
    List<Contact> contactList = t;
    JSONArray listOfIds = new JSONArray();

    for (Contact c: contactList) {
        listOfIds.put(c.getId());
    }
    AppDataManager manager = AppDataManager.getInstance(getSherlockActivity());
        manager.setFacebookFriendsIds(listOfIds);
        manager.setFacebookFriends(contactList);

}

}

At this point I have a List that I can work with.

Walter
  • 5,867
  • 2
  • 30
  • 43
0

https://developers.facebook.com/tools/

Use Graph Api Search .

https://graph.facebook.com/YOUR_ID?fields=friends , will show you whole list of friends .

https://graph.facebook.com/YOUR_ID?fields=friendlists , will show you only 25 friends .

Tushar Pandey
  • 4,557
  • 4
  • 33
  • 50
  • thanks @Thushar, is there any example to access friends list using social auth? I am using this library code.google.com/p/socialauth-android. – Jagdish Dec 17 '13 at 13:01
0

This is the correct answer: add this to your oauth_consumer.properties file, under the line containing graph.facebook.com.consumer_secret:

graph.facebook.com.custom_permissions = user_friends

or read_friendlists depending on what permissions you truly need.

Check https://developers.facebook.com/docs/facebook-login/permissions/v2.0 for more info about permissions.

Karim
  • 5,298
  • 3
  • 29
  • 35