Monday, September 5, 2011

To get full size profile picture from facebook

The default profile picture from Facebook API:

Use this link:
http://graph.facebook.com/<user.id>/picture?type=large
(note:without using type variable you will receive a 50x50 image of user)

The Full Size profile picture:

Assumptions

The following scripts assume a couple of things:

Graph API method

The following Graph API method works by doing two API calls: The first requests all the user albums and gets the ID of the album with the name “Profile pictures”, the second gets the first image from that album. Conveniently, the current profile picture is always the first in the returned list.
//Get a list of all the albums FB.api('/me/albums', function (response){ for (album in response.data) { // Find the Profile Picture album if(response.data[album].name == "Profile Pictures"){ // Get a list of all photos in that album. FB.api(response.data[album].id + "/photos", function(response){ //The image link image = response.data[0].images[0].source; }); } } });

FQL method

The FQL method also requires two api calls: one to get the user id, and a second FQL query for that user’s profile picture. You could lower this to one API call if you store the user id sometime earlier.
//get the current user id FB.api('/me', function (response){ /* the FQL query: Get the link of the image, that is the first in the album "Profile pictures" of this user.*/ var query = FB.Data.query('select src_big from photo where pid in (select cover_pid from album where owner={0} and name="Profile Pictures")', response.id); query.wait(function (rows){ //the image link image = rows[0].src_big; }); });

No comments:

Post a Comment