Getting the user's friend list
Now that we know how to make requests to the Facebook API and get it to update correctly in our views, let's now see how to get the list of friends of the logged-in user.
We will create our function named loadFriends
and call it within the controller
option of the myFriends
directive, as shown in the following code snippet:
controller: function($scope) { $scope.loadFriends = function() { FB.api('/me/friends', function(response) { $scope.$apply(function() { $scope.myFriends = response.data; console.log($scope.myFriends); }); }); }; }
As you can see, the $scope.loadFriends
function loads the FB.api
method, making a request to the me/friends
end point.
The response from the request is stored in the $scope.myFriends
scope ...
Get AngularJS Web Application Development Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.