0

I'm testing how all the facebook api calls work, and I need to know how it is possible to print user_friends on a page, after the user gives permission.

I wrote this code, in order to try and print the user_friends feilds:

  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.user_friends + '!';
    });
  }

At the end, I added response.user_friends, however I don't get the user friends list printed on the page, instead I get "undefined".

If I change it to response.name, it work and the name of the user is printed.

P.S. In the log in button I requested the user friends list:

<fb:login-button scope="public_profile,email,user_friends" onlogin="checkLoginState();">
</fb:login-button>

It is just a test for me to understand how the user_friends look like, I'm not going to do so in the actual app. So Why I'm not getting the user_friends printed at the page?

Thanks

  • 1
    You will not get the friends with a simple call to `/me`, you have to request the specific “edge”, `/me/friends`. – CBroe Mar 21 '15 at 13:52

1 Answers1

0

You have to authorize the user with the correct permission (user_friends) before making any API call. See those links for more information about user authorization with the JavaScript SDK:

After that, you can use /me/friends to get the friends of the authorized user. Keep in mind that you can only get the friends who authorized the App too, for privacy reasons. More information about that can be found in the following thread: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130