I'm interested in getting the user's friend list in my android application on facebook login. Can anyone please guide me as to what needs to be done? Since Facebook made new changes in he Graph API on the 10th of July. I'm a little hesitant in trying out the solutions provided earlier. A detailed guide is what I need.
Asked
Active
Viewed 57 times
1 Answers
0
try this to get friend list from facebook.
GraphRequest.newMyFriendsRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
@Override
public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) {
Utils.setLog("response :+" + jsonArray.toString());
} catch (Exception e) {
//Exception Track
e.printStackTrace();
}
}
}).executeAsync();
before make sure you have to ask permission for user_friends
from facebook
.

Mehul Kabaria
- 6,404
- 4
- 25
- 50
-
Hi. Thank you so much. Where exactly should I write this piece of code? Also, I tried asking for user_friends permission. But the app I'm working on uses a custom button and not the facebook widget. Thus the conventional way doesn't work. COuld you please help with that? – Faiza Ahmad Jul 13 '17 at 07:10
-
private String[] mFacebookPermissions = {"public_profile", "email", "user_birthday", "user_location","user_friends"}; will this piece of code suffice? – Faiza Ahmad Jul 13 '17 at 07:14
-
you have to put that facebook widget with visibility invisible/gone and when you click your custom button then you have to write `facebook_widget..performClick();` – Mehul Kabaria Jul 13 '17 at 07:15
-
yes, before you ask permission, first you have to do with login with facebook. – Mehul Kabaria Jul 13 '17 at 07:16
-
Hey, how exactly should I add this invisible widget on top of my custom button (which is a relative layout)? – Faiza Ahmad Jul 13 '17 at 07:50
-
Hi! I managed to add the invisble facebook LoginButton widget and made it invisible in the xml file. However, I havean isssue, while writing this.--- – Faiza Ahmad Jul 13 '17 at 08:21
-
LoginButton authButton = (LoginButton) view.findViewById(R.id.loginFacebookButton); Here, findViewById is not recognized. What should I do? – Faiza Ahmad Jul 13 '17 at 08:23
-
you facebook widget is invisible so no need where you put in xml. you can put anywhere in xml. – Mehul Kabaria Jul 13 '17 at 08:29
-
Hey Mehul, I also wanted to ask that do I need to create a separate page which shows me the friends I have on facebook as well as my app and whether I should connect with them. Or does the facebook sdk do that automatically fo me – Faiza Ahmad Jul 13 '17 at 09:56
-
can't understand what you want exactly. – Mehul Kabaria Jul 13 '17 at 10:57