Alessia Pileri
Alessia Pileri

Reputation: 11

Facebook api friends list

I'm using Facebook's javascript SDK to inspect the friends list of users registered in my application.

I have this call:

     FB.getLoginStatus(function (response) {
        if (response.status == 'connected') {     
           FB.api('me/friends', { fields: 'id, first_name, picture', limit: 6 },function(response){
                  MY CODE TO VIEW FRIENDS PICTURE
           });
        }
        else{
                 CODE TO GET ACCESS_TOKEN
        }
  });

but in most of cases I get an api error like this:

response.error = {
message: unkown error,
code: undefined,
type: http,
subcode: undefined
}

I tested it with my account and it works fine, even if I change privacy permission as friend's sharing.

There is something wrong in my code?

Upvotes: 1

Views: 7310

Answers (2)

Mohammed Alaghbari
Mohammed Alaghbari

Reputation: 439

Why don't you use an fql query with FB.api? It offers a great control.

The following FQL return (User ID, First Name and Picture of a friend who is using the application)

FB.api(
         {
           method: 'fql.query',
           query: 'SELECT uid,first_name,pic FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) and is_app_user limit 6',
           access_token: token
         }

Note: You would better use this condition

if (response && response.authResponse) {

Instead of:

if (response.status == 'connected') {

Regards,

Upvotes: 0

Jay Hardia
Jay Hardia

Reputation: 746

FB.api('me/friends', { fields: 'id, first_name,picture', limit: 6 },function(response){

    console.log(response);

  });

For more detail information use Facebook's graph API explore :Facebook Graph aPI

Upvotes: 1

Related Questions