Попытка получить данные из нескольких вызовов FB в один массив и работать с ним при готовности. К сожалению. Скрипт ждет ответа, но каким-то образом я не могу получить к нему доступ позже.
var xxx = 0; // Counter to check
var friendsRequest = []; // Array to catch all calls and execute the code when all responses are back
var friends = ['...','...']; // array of friend id's
for (var i = 0; i < friends.length; i++) {
var friend = friends[i]; // Go through number of FB friends (doesn't matter)
// Here we save all calls to wait for result
friendsRequest[friend] = FB.api('/' + friend + '/picture?redirect=0&height=64&type=square&width=64', function(response) {
xxx++; // Try to increment the counter
console.log(xxx); // Works fine.
});
}
// Execute the code when all data collected.
// It executes correctly __after__ last FB.api() async call ends
$.when(friendsRequest).then(function(){
console.log(xxx); // But here we have always "0"
});
Может быть, $ .когда каким-то образом не работает с несколькими вызовами FB.api ()? Любые идеи, что не так?