luiscarlosjayk/angular-facebook

When is it possible to get user details from Facebook?

mrdziuban opened this issue · 5 comments

In my code I'm trying to populate the user data on page load after isReady returns, like this:

$scope.$watch(function() {
  return Facebook.isReady();
}, function(newVal) {
  if (newVal) {
    $scope.facebookIsReady = true;
    $scope.api();
  }
});

but Facebook always returns an OAuthException (error code 2500) saying "An active access token must be used to query information about the current user."

If I change the line $scope.api(); to read $timeout($scope.api, 1000); then it works properly.

How can I tell when I'm able to retrieve the logged in user's data from Facebook?

Hi, I have exactly the same issue!
Did you find something better than the timeout hack ?
thank you in advance :)

Hey @benavern, I ended up using Satellizer instead, which included support for all the social networks I was using. Hope that helps!

The solution is indeed pretty simple, there are listeners for which names have been mapped to simplified/shorter ones (https://github.com/Ciul/angular-facebook/blob/master/lib/angular-facebook.js#L489). Thus, you could listen to the login event on your controller and then take action on that moment. So, as you can see, events has been covered here too ;)

Try the getLoginStatus method too, that's how you could make sure there's an user logged or not in your app.

The reason why it wasn't working (I think) is because the fact that the Api is ready to listen for calls doesn't mean that the user info (if there's one logged in your app) has been retrieved yet.

Hope that helps :]

Sorry but I ended up by using ngFacebook instead. Thank you though

Oh that's great, so you could solve it.

Regards