In my Application i want to Get the Friends list of Facebook. Is it possible to get the Friends list from Facebook SDK. I tried a lot but i am not get succeeded. Can any one help me how to do this.
Asked
Active
Viewed 2,489 times
-1
-
please look at the duplicate link, it explains every possibility to get friends – andyrandy Jun 15 '16 at 12:54
2 Answers
1
Yes of course it is possible in android with Graph Api
But for the security purpose the condition is that you only get the list of friend which is using your app. Refer This Link also check this tutorial and this answer
Following is some code snippet after login you will get
GraphRequestAsyncTask graphRequestAsyncTask = new GraphRequest(loginResult.getAccessToken(),"/me/friends",bundle, HttpMethod.GET,new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
JSONArray rawName = response.getJSONObject().getJSONArray("data");
friendList = "{\"friendlist\":" + rawName.toString() + "}";
//String friendlist = rawName.toString() ;
Log.d("TAG","response of friendlist is : " + friendList);
/* //coding for insert data in db.
String result = JSONUtils.insertUserprofile(imagePath, name, fbid, friendList);
Log.d("TAG", "Result of fb is : " + result);
if (result.toLowerCase().contains("success")) {
myPreferences.setFBUserId(Constant.PREFERENCE_LOGIN_FB, fbid);
//LoginManager.getInstance().logOut();
}*/
} catch (JSONException e) {
e.printStackTrace();
}
}
}).executeAsync();

Community
- 1
- 1

Ajay Pandya
- 2,417
- 4
- 29
- 65
-
-
Yes exactly that was written bymistake and its a list who using your app :) you can edit answer dude. – Ajay Pandya Jun 15 '16 at 12:55
0
login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
if (AccessToken.getCurrentAccessToken() != null) {
RequestData();
}
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
}
});
Request Data
private void RequestData() {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object,GraphResponse response) {
new GraphRequest(
AccessToken.getCurrentAccessToken(),
// "/me/friends",
//"me/taggable_friends",
"me/invitable_friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
JSONArray rawName = response.getJSONObject().getJSONArray("data");
Log.e(TAG,"Json Array Length "+rawName.length());
Log.e(TAG,"Json Array "+rawName.toString());
for (int i = 0; i < rawName.length(); i++) {
JSONObject c = rawName.getJSONObject(i);
String name = c.getString("name");
Log.e(TAG, "JSON NAME :"+name);
JSONObject phone = c.getJSONObject("picture");
Log.e(TAG,""+phone.getString("data"));
JSONObject jsonObject = phone.getJSONObject("data");
String url = jsonObject.getString("url").toString();
Log.e(TAG,"@@@@"+jsonObject.getString("url").toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,email,picture");
request.setParameters(parameters);
request.executeAsync();
}

Vanraj Ghed
- 1,261
- 11
- 23