I have a problem with the Facebook API. I may not be going the about this the best way, but here is what I’ve got.
I have a array of request_ids, which I need to convert to user Ids.
I have a while loop which queries the request ids and gets the user id.
function (response) {
var requestsToSend = new Array();
var i = 0;
while (i < response.request_ids.length)
{
FB.api('/'+response.request_ids[i], function(res){
requestsToSend[i] = res['to']['id'];
});
i++;
}
console.log(requestsToSend[0], requestsToSend[1], requestsToSend[2], requestsToSend[3]);
}
This works fine. However, when I echo the returned ids (console.log) they are undefined, because the FB.api hasn’t yet returned the values/responses.
Is there any way to fire the console.log only once the FB.api has returned values?
I don’t really want to set a timer to fire the function.
Iv fixed the issue but not very happy with the solution