Newibe
Newibe

Reputation: 49

Fetching list of user's friends for website

I have implemented Fb login for my website. Also for the Fb page of my app inside approved items it shows - user_friends Provides access to a person's list of friends that also use your app. This permission is approved by default.

How can I get the list of friends of the user who is there on my app ?

Also When I try to do this --

FB.api(
    "/me/friends",
    function (response) {
     if (response && response.data){
        alert(response.data);
      } else {
        console.log('Something goes wrong', response);
      }
    }
);

I get no response.

Thanks, Newbie

Upvotes: 0

Views: 534

Answers (1)

andyrandy
andyrandy

Reputation: 74014

First, you need to include and initialize the JavaScript SDK: https://developers.facebook.com/docs/javascript/quickstart/v2.2

Then, you need to authorize the user: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0

(don´t forget to use the scope parameter with the "user_friends" permission)

After that, you can call FB.api('/me/friends'... to get the friends of the user who authorized the App too.

You can also test /me/friends in the API Explorer, just select the correct App: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Ffriends&version=v2.2

Upvotes: 1

Related Questions