Does anyone know how I can get a thumbnail/avatar of a facebook user using the javascript sdk?
I know to get the full size picture I can do the folllowing:
//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;
});
}
}
});
Not sure on how to get the thumbnail/avatar size. Something like a 50x50 size
You can also just use an <img>
tag with a special URL to do the same thing:
<img src="http://graph.facebook.com/<UID>/picture?type=square" />
As of August 2012, you can define custom dimensions for the user thumbnail, e.g. https://graph.facebook.com/USER_ID/picture?width=WIDTH&height=HEIGHT
. Find out more, https://developers.facebook.com/docs/reference/api/using-pictures/.
I did the following to accomplish the same thing:
FB.api( { method: 'fql.query', query: 'SELECT name,email,pic_small FROM user WHERE uid=' + uid // uid is the id of the user. }, function(response) { var user = response[0]; // user.pic_small contains the url for the small sized profile pic });
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