怎么获取好友的名字

How to get friends name

我正在使用此代码:

   function login() {

       FB.login(function(response) {
           if (response.authResponse) {
               console.log('Welcome! Fetching your information.... ');

               FB.api('/me/friends', {
                   fields: 'id,name'
               }, function(response) {
                   for (element in response) {
                       console.log(element.name);
                   }
               });


           } else {
               console.log('User cancelled login or did not fully authorize.');
           }
       }, {
           'scope': 'user_friends'
       });
   }

但我在控制台中收到此响应:

Welcome! Fetching your information.... 
2 undefined

为什么?

编辑:

我刚刚编辑了上面的代码:

   function login() {

       FB.login(function(response) {
           if (response.authResponse) {
               console.log('Welcome! Fetching your information.... ');

               FB.api('/me/friends', {
                   fields: 'id,name'
               }, function(response) {
                   console.log(response.summary);
                   console.log(response);
                   for (element in response.data) {
                       console.log(element.id);
                   }
               });


           } else {
               console.log('User cancelled login or did not fully authorize.');
           }
       }, {
           'scope': 'user_friends'
       });
   }

但现在我收到了这样的回复:

Welcome! Fetching your information.... 
Object {total_count: 58}
Object {data: Array[0], summary: Object}

不可能再得到所有朋友了。您也只能获得使用user_friends权限授权您的应用程序的朋友。

正确的代码是:

FB.api('/me/friends', {
   fields: 'id,name'
}, function(response) {
   for (element in response.data) {
       console.log(element.name);
   }
});

更多信息:Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app