2016-08-12 7 views
-1

친구의 이름을 얻을 수 있습니다 :어떻게이 코드를 사용하고

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} 
+1

입니다

이 올바른 코드 것입니까? – WizKid

+0

@WizKid가 응답과 함께 질문을 편집했습니다. – xRobot

+0

응답이 정확합니다. 아직 친구를 승인 한 친구가 없습니다. – luschn

답변

1

그것은 더 이상 모든 친구를 얻을 수 없습니다. 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

+0

친구의 ID를 얻을 수있는 방법이 있습니까? – xRobot

+0

그 친구가 내 앱을 승인 한 경우에만 내 대답을 읽을 수 있습니다. 내 대답에있는 링크의 대답을 읽으십시오. – luschn