Q:

Updating friends using facebook login SDK?

I am trying to create a website that shows a user's Facebook friends that're also using the site. When a user logs in to my site using Facebook I fetch the user's friends (via the access token) and save them to my database.
Whenever a new user that is friends with the old user creates an account, I want to insert the new user to the existing user's friends list in my database. The problem is that whenever a existing user logs in from my custom login page they aren't logging in through Facebook, and so I can not get an updated access token. As the site is now, it shows the list of friends, but without people who have signed up later than the original user.
Seeing as access tokens change, how can I insert a new user to the existing user's friends list whenever the new user joins the site, as existing users will login through my page not through Facebook login?

A:

One way to solve this is to store an Extended User Token and use that one to refresh the friend list from time to time. It is valid for 60 days.
Better: The user does not have to use a Facebook Login button to reauthorize, you can use FB.getLoginStatus of the JavaScript SDK to refresh the User Session/Token when the user hits your website, completely in the background. Check out the docs for an explanation about that, that is how it should work:
FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    FB.api('/me/friends', function (response) {
      console.log(response);
    })
  }
});

Keep in mind that this is just a basic example of how it work, of course you should not refresh the friend list on EVERY page refresh.

