Load And Save Facebook Profile Picture Of User
Posted by in Facebook Graph API November 7, 2011 2 Comments

There is an easy way to display Facebook Profile Picture if you already know their Facebook ID or Username. By using Facebook Graph API, you can get your own/anyone profile picture in 2 type of sizes: default(small) and large.

This method is public so you or your users aren’t be required to allow app permission or anything. And you can load any Facebook profile picture you want as long as you know their Facebook ID or Facebook username. Note that not all Facebook users register their username therefore using Facebook ID is better.

1. Display Facebook Profile Picture of User

In order to load Profile Picture of a particular Facebook user, simply access the picture from a URL below and as I mentioned above, we can display it in 2 difference sizes: small and large.

+ Small:

http://graph.facebook.com/hoanhuynhtrong/picture
http://graph.facebook.com/1258565465/picture

+ Large:

http://graph.facebook.com/hoanhuynhtrong/picture?type=large
http://graph.facebook.com/1258565465/picture?type=large

Using Facebook ID or Username will return the same result and just replace my username(hoanhuynhtrong) or ID(1258565465) with the username or ID you want to display their profile picture.

2. Save Profile Picture to file

In order to save the external picture somewhere in your web server, you can use a simple ASP.NET or PHP script to do it. Below is a PHP example:

<?php
	$fid = "hoanhuynhtrong";
	$img = file_get_contents("https://graph.facebook.com/" . $fid . "/picture?type=large");
	$file = dirname(__file__). "/" . $fid . ".jpg";
	file_put_contents($file, $img);
?>

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com
  • http://www.bing.com/ Deliverance

    Mighty useful. Make no mistake, I apeprciate it.

  • adi

    it’s not working…… :(