2016-08-12 12 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

関連する問題