I am attempting to interact with the Facebook API using AngularJS.
The issue I'm facing is that all API calls from Facebook are asynchronous, so I need a way to determine when my query on Facebook is ready to be used in AngularJS.
To address this, I have implemented the following method in my controller:
Facebook.getLoginStatus();
This 'Facebook' service is defined as follows:
app.factory('Facebook', function() {
getLoginStatus: function() { FB.getLoginStatus(function(stsResp) { console.log(stsResp); if(stsResp.authResponse) { // User is already logged in return true; } else { // User is not logged in. return false; } }); }
}
In this scenario, my goal is to check if the user is logged in. If it is true, I will display certain options; otherwise, I will show the Login button.
I have attempted using $q.defer() functions, promises, and factories to monitor response data, but nothing seems to work as intended. I have reviewed some learning resources like examples from Egghead.io, but I believe I still lack full understanding of asynchronous calls in AngularJS.
Thank you in advance.