从 Facebook JavaScript SDK 中的每个相册中只提取一张(第一张或最后一张,不管)照片是真的吗?
我试图为每张专辑制作一个周期,但我认为为每张专辑向 Facebook 发出请求并不是一个好主意,特别是如果用户有 50 张或更多专辑。我需要它在每个专辑旁边显示缩略图。
我尝试了什么:
FB.api('/me/albums?access_token='+response.authResponse.accessToken,function(response){
if(response.error){
alert(response.error);
}
else {
var albums = new Array();
albums = response.data;
var albumsCount = albums.length;
var albumsString = "";
var i = 0;
for(i = 0; i<albumsCount;i++){
//Here is that bad idea with requests in every cycle
FB.api('/'+albums[i].id+'/photos?access_token='+FB.getAuthResponse().accessToken,function(response){
if(response.error) {
alert(response.error);
}
else {
var photo=response.data;
var photoHere="<img src='"+photo[i].picture+"'>";
}
});
//End of bad idea
albumsString+="<a href='#' return false'>"+albums[i].name+"</a><br/>";
}
var toHTML="List of your albums: "+albumString+"<br/>";
document.getElementById("resultAlbums").innerHTML=toHTML;
}
});