I am using Facebook sdk 4.4.0 in android and I want to get current profile picture of the user using graph request. How to do that?
I have seen that people use
https://graph.facebook.com/me/picture?access_token=ACCESS_TOKEN
API to extract profile picture but I cant figure how to extract profile picture from it.
You can download all photos at once from Facebook only within your profile account or page, regardless of whether you're using a browser or the mobile app version of Facebook. In the Facebook app or within a browser, navigate to “Settings,” then tap/click on “Your Facebook information.”
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();
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");
}
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With