How to get friend list from Facebook using Android Facebook sdk?
Are you trying to get the Facebook friendlist of the user logged in into your app? Sounds like you need to perform a facebook graph request to acquire that list, and then withdraw the friends you want.
https://developers.facebook.com/docs/graph-api/reference/user/friendlists/
If you wanted to do it in Android java, her is an example:
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest graphRequest = GraphRequest.newMeRequest(token, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
try {
JSONArray jsonArrayFriends = jsonObject.getJSONObject("friendlist").getJSONArray("data");
JSONObject friendlistObject = jsonArrayFriends.getJSONObject(0);
String friendListID = friendlistObject.getString("id");
myNewGraphReq(friendListID);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle param = new Bundle();
param.putString("fields", "friendlist", "members");
graphRequest.setParameters(param);
graphRequest.executeAsync();
Since "member" is an edge in "friendlist" you can do a new request with your friendlist Id to get the members of that particular friend list. https://developers.facebook.com/docs/graph-api/reference/friend-list/members/
private void myNewGraphReq(String friendlistId) {
final String graphPath = "/"+friendlistId+"/members/";
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest request = new GraphRequest(token, graphPath, null, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
JSONObject object = graphResponse.getJSONObject();
try {
JSONArray arrayOfUsersInFriendList= object.getJSONArray("data");
/* Do something with the user list */
/* ex: get first user in list, "name" */
JSONObject user = arrayOfUsersInFriendList.getJSONObject(0);
String usersName = user.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle param = new Bundle();
param.putString("fields", "name");
request.setParameters(param);
request.executeAsync();
}
In the documentation for Facebook Graph request you can see what you can do with the User objects. I don't have enough rep to post another link unfortunately.
Keep in mind that a user must have signed in with facebook to get the access token needed to do these operations.
Well, hope it was something remotely like this you were looking for.
Edit: this method does not work anymore, the first link about friendlists shows that it is deprecated since 4 April 2018.
How do I get friends list from FaceBook?
The correct API endpoint to get the friends of the authorized user is /me/friends
and you need to authorize with the user_friends
permission. Keep in mind that you will only get friends who authorized your App with user_friends
too.
You can ONLY get access to ALL friends for tagging (with /me/taggable_friends
) or inviting friends to a game with Canvas implementation (with /me/invitable_friends
).
More information: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
Android Facebook SDK How to get all friends list who installed my app
Try this. Please make sure your read permissions include user_friends
as follows
loginButton.setReadPermissions("email", "public_profile","user_friends");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
}
});
Then get friends like this
GraphRequest request = GraphRequest.newMyFriendsRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
@Override
public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) {
}
});
or by get request
String urll="https://graph.facebook.com/v2.7/me/friends?access_token="+ user accesstoken;
Refer:- https://coderzpassion.com/android-using-facebook-login-application-using-latest-facebook-sdk/
How can I make to get friends list android app on Facebook?
Facebook SDK new version disable "Get friend list" api. U just can get list of friend who use ur application.
You can research about graph api here to know which parameter to pass: Document for graph api
Test graph api
And you have to provide login facebook function to use these api
FirebaseAuth android get Facebook friends list
generally obtaining user's all friends list from Facebook is not possible, they removed this option years ago, with API v2.0 introduction... more info about and useful suggestions HERE
there is an official FB API called Graph API and HERE you have some doc about friend lists
and the Firebase... well, this is Google's product and it have nothing to do with Facebook... You are probably using FB mail address for creating an account in Firebase service/database, but it is keeping only this data plus some additional attributes if set (like photo or visible name).
firebaseAuth.getCurrentUser()
returns FirebaseUser
object, which have THESE methods - like you see: logpass, name, photo url and only few more methods. no option for getting friends list, because there is no method to set them, and no possibility to get this list from FB lib/API
Android: get facebook friends list
You are about half way there. You've sent the request, but you haven't defined anything to receive the response with your results. You can extend BaseRequestListener
class and implement its onComplete
method to do that. Something like this:
public class FriendListRequestListener extends BaseRequestListener {
public void onComplete(final String response) {
_error = null;
try {
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
FacebookActivity.this.runOnUiThread(new Runnable() {
public void run() {
// Do stuff here with your friends array,
// which is an array of JSONObjects.
}
});
} catch (JSONException e) {
_error = "JSON Error in response";
} catch (FacebookError e) {
_error = "Facebook Error: " + e.getMessage();
}
if (_error != null)
{
FacebookActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Error occurred: " +
_error, Toast.LENGTH_LONG).show();
}
});
}
}
}
Then in your request you can specify the request listener to use for receiving the response from the request, like this:
mFacebook.request("me/friends", bundle, new FriendListRequestListener());
Get Facebook Friend List with Name
I got solutions for using this
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/taggable_friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("getFriendsDat",""+ response);
}
}
).executeAsync();
You will get friend list with name and detail.
you have to add user_friends
permission and need to submit your app for review.
Related Topics
Outofmemory Exception When Loading Bitmap from External Storage
Listview Items Are Not Clickable. Why
Android Datepickerdialog: Set Min and Max Date for Selection
Batch Scripting - If Exist ./Sdcard/File.Any Using Adb
Call Getlayoutinflater() in Places Not in Activity
How to Provide Different Android App Icons for Different Gradle Buildtypes
Android: Cloning a Drawable in Order to Make a Statelistdrawable with Filters
Android Layout Animations from Bottom to Top and Top to Bottom on Imageview Click
Single Observable with Multiple Subscribers
Center Align Title in Action Bar Using Styles in Android
How to Display Gif in React-Native Android App
Android - Detecting Application Launch from Home or History
Which View Should Be Used for New Material Design Bottom Navigation
Moving or Copying Data from One Node to Another in Firebase Database