How to get Facebook profile image in Android
You need to call GraphRequest API for getting all the details of user in which API also gives URL of current profile picture.
Bundle params = new Bundle();
params.putString("fields", "id,email,gender,cover,picture.type(large)");
new GraphRequest(AccessToken.getCurrentAccessToken(), "me", params, HttpMethod.GET,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (response != null) {
try {
JSONObject data = response.getJSONObject();
if (data.has("picture")) {
String profilePicUrl = data.getJSONObject("picture").getJSONObject("data").getString("url");
Bitmap profilePic= BitmapFactory.decodeStream(profilePicUrl .openConnection().getInputStream());
mImageView.setBitmap(profilePic);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).executeAsync();
Get Image From Facebook
String image_url = "http://graph.facebook.com/" + Profile.getCurrentProfile().getId() + "/picture?type=large";
Glide.with(activity)
.load(image_url)
.into(imageView);
dependency
implementation 'com.github.bumptech.glide:glide:4.1.1'
You can have this in 2 different way.
Way1: Integrate graph api support https://developers.facebook.com/docs/graph-api/reference/user/picture/
Way2: Via Get Call http:// graph.facebook.com/{facebook-Id}/picture?width=x&height=y
where x and y could be any integer e.g. 100
From last sdk 4.5.0
String url;
Bundle parametersPicture = new Bundle();
parametersPicture.putString("fields", "picture.width(150).height(150)");
GraphResponse lResponsePicture = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/",
parametersPicture, null).executeAndWait();
if (lResponsePicture != null && lResponsePicture.getError() == null &&
lResponsePicture.getJSONObject() != null) {
url = lResponsePicture.getJSONObject().getJSONObject("picture")
.getJSONObject("data").getString("url");
}