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
您也可以只使用<img>
标记和特殊URL来执行相同的操作:
<img src="http://graph.facebook.com/<UID>/picture?type=square" />
As of August 2012, you can define custom dimensions for the user thumbnail, eg 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 });
Since you have the UID of the person, you can easily get the image. For example, my profile image URL should be graph.facebook.com/v2.8/1375341351/picture?type=small (now change the type parameter and enjoy different sizes.. cheers... sizes can be small, normal, album, large, square
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.