I have a application in which I have to
FB.api(/me)
FB.api(/me/friends).
I want once the user is authenticated to login to a new page for which I will be having window.location.href.(xx).
so my pesduocode is :
checkuserdetails()
{
FB.api(/me)
FB.api(/me/friends).
window.location.href.(xx).
}
I have alerts in the call back functions and they never get executed and the page gets redirected. as suggested by CBroe I have kept the window.location.href. in the cal back.
But that is also having issues.
its like thiis:
pseduo code:
checkuserdetails()
{
FB.api(/me)
FB.api(/me/friends){ window.location.href.(xx).}.
}
The Alerts in friends will never get executed.
pseduo code:
checkuserdetails()
{
FB.api(/me) { window.location.href.(xx).}.
FB.api(/me/friends)
}
Both alerts are executed.
my questions:
1) some times I see alerts from /me/friends getting executed first and some times in /me. I understand FB is asyncronous how to make ut sequentical…If I have lot of FB.api calls (more than 2) how where to keep the windows.location? how to control the asyncronous functionality
All API calls are asynchronous, so if you need to execute something after all of these have completed then you need to either make them execute in series (not advised for perf), or in parallell with synchronization.
For this you can use patterns such as Promises, or Futures, or something as simple as
This can of course be abstracted into some helper functions..