How to get large profile picture from Facebook’s Graph API

For making facebook applications we often need to fetch the profile pictures of the users.

Here is the simple endpoint to fetch user’s profile picture

graph.facebook.com/me/picture

But by default it will return the picture of very small size. So we need to define the size of image we are interested in

graph.facebook.com/me/picture.type(large)

It can be small,album,normal or large. But even this large image is very small though bigger than small one

Another way is to specify the minum width like this

graph.facebook.com/me/picture.width(640)

And if we want to fetch other images apart from profile pic and we have the ID of the picture, we can use this code to fetch the biggest one. This API call will return multiple images along with their dimensions. We just need to iterate and keep the largest one

JsonObject jj = client.fetchObject(id, JsonObject.class,Parameter.with("fields", "images"));
JsonArray j = jj.getJsonArray("images");
String source = "";
int height = 0;
for (int c = 0; c < j.length(); c++) {
						JsonObject io = j.getJsonObject(c);
						int h = io.getInt("height");
						if (h > height) {
							height = h;
							source = io.getString("source");
						}
					}

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *